<?php
/*
ВАЖНО!!! - НЕ сохранять в ютф!!! если есть русские буквы в никах, для авторизации
*/

set_time_limit(300);

define('IN_PHPBB', true);
define('BB_ROOT', './');
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require(BB_ROOT ."common.php");
require(INC_DIR .'bbcode.php');
require(INC_DIR .'functions_post.php');
require(INC_DIR .'functions_torrent.php');
require(INC_DIR .'class.snoopy.php');

$url = isset($_POST['url']) ? $_POST['url'] : '';
$url = str_replace('http://www.', 'http://', $url);
$hidden_form_fields = $message = $subject = '';

$forum_id = (int) request_var('forum_id', '');

if(!$url)
{
    // Start session management
	$user->session_start();

    if (IS_ADMIN)
	{
		$forum_select_mode = 'admin';
	}
	else
	{
		$not_auth_forums_csv = $user->get_not_auth_forums(AUTH_VIEW);
		$forum_select_mode = explode(',', $not_auth_forums_csv);
	}

    $template->assign_vars(array(
        'URL'          => true,
        'SELECT_FORUM' => get_forum_select($forum_select_mode, 'forum_id', 0),
    ));
}
else
{
    // Start session management
	$user->session_start(array('req_login' => true));
	
			function pic_uploud_url($img, $align=false)
		    {
				global $bb_cfg;

				$dir = $bb_cfg['pic_dir']; //туда грузится будет
		        $allowed_ext = array('jpeg', 'jpg',	'png', 'gif');

				$filetype = substr(strrchr($img, '.'), 1);
				if (@fopen($img, "r") && in_array($filetype, $allowed_ext))
				{
					$filename = substr(strrchr($img, '/'), 1);
			        copy($img, $dir . $filename);

					$new_img = make_url('/') . $dir . $filename;

					return "[img$align]". $new_img . "[/img]";
				}
		    }

    if($_POST['tracker'] == 'rutracker')
    {
	    if (!preg_match("/http:\/\/rutracker.org\/forum\/viewtopic.php\?t=/", $url))
	    {
	    	meta_refresh('', '2');
	    	bb_die("false link<script>alert('false link http://rutracker.org/forum/viewtopic.php?t=xxxx');</script>");
	    }

	    $snoopy = new Snoopy;
		$snoopy->host = "rutracker.org";
		$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
		$snoopy->referer = "http://rutracker.org/";
		$snoopy->rawheaders["Pragma"] = "no-cache";

		$submit_url = "http://login.rutracker.org/forum/login.php";
		$snoopy->_submit_method = "POST";
		$submit_vars = array (
			'login_username' => "Artem1143", //логин
			'login_password' => "333435", //пароль
			'login' => $lang['LOGIN'],
		);
		$snoopy->submit($submit_url, $submit_vars);

	    $snoopy->_httpmethod = "GET";
	    $snoopy->fetch($url);
	    $content = iconv('windows-1251', 'UTF-8', $snoopy->results);
	    $pos = strpos($content, '<form method="post" action="thx.php">');
		$content = substr($content, 0, $pos);

	    if (!$content)
	    {
	    	meta_refresh('', '2');
	    	bb_die('false content');
	    }

	    function rutracker($text, $mode=false)
		{
			if($mode == 'title')
			{
				preg_match_all ('#<h1 class="maintitle"><a href=".*?">([\s\S]*?)</a></h1>#', $text, $source, PREG_SET_ORDER);
			    $text = @$source[0][1];
				$text = str_replace('<wbr>', '', $text);
		    }
		    elseif($mode == 'torrent')
		    {
		    	preg_match_all ('#<a href="http://dl.rutracker.org/forum/dl.php\?t=(.*?)" class#', $text, $source, PREG_SET_ORDER);
			    $text = $source[0][1];
		    }
		    else
		    {
				$pos = strpos($text, '<div class="post_body"');
				$text = substr($text, $pos);
				$pos = strpos($text, '<div class="clear"></div>');
				$text = substr($text, 0, $pos);
				$text = preg_replace('/<div class="post_body" id=".*?">/', '', $text);

				$text = preg_replace('#<img class="smile" src=".*?" align="absmiddle" border="0" />#', '', $text);
				$text = preg_replace('#\n<h3 class="sp-title">.*?</h3>#', '', $text);
				$text = str_replace('<div class="q-wrap">', '', $text);
				$text = str_replace('<div class="sp-wrap">', '', $text);
				$text = str_replace('<div class="c-wrap">', '', $text);
				$text = preg_replace('#<a name=".*?"></a>#', '', $text);
				$text = preg_replace('#<a class="postLink-name" href=".*?">([\s\S]*?)</a>#', '$1', $text);
				$text = str_replace('<span class="post-hr">-</span>', "\n[hr]\n", $text);
                $text = preg_replace('#<pre class="post-pre">([\s\S]*?)</pre>#', '$1', $text);
				$text = preg_replace('#<div style="margin-.*?">([\s\S]*?)</div>#', '$1', $text);
				$text = preg_replace('/<var class="postImg" title="(.*?)">&#10;<\/var>/', '[img]$1[/img]', $text);
				$text = preg_replace('/<var class="postImg postImgAligned img-(.*?)" title="(.*?)">&#10;<\/var>/', "[img=\\1]\\2[/img]\n", $text);
				$text = str_replace('<span class="post-br"><br /></span>', "\n\n", $text);

				$text = preg_replace('/<br.*?>/', '', $text);
				$text = preg_replace('/<ul type="(.*?)">/', '[list=$1]', $text);
				$text = str_replace('<ul>', '[list]', $text);
				$text = str_replace('</ul>', '[/list]', $text);
				$text = str_replace('<li>', "\n[*]", $text);
				$text = str_replace('</li>', '', $text);

                $text = str_replace('&#039;', "'", $text);
				$text = str_replace('&nbsp;', ' ', $text);
				$text = str_replace('&gt;', '>', $text);
				$text = str_replace('&lt;', '<', $text);

				for ($i=0; $i<=20; $i++)
				{
					$text = preg_replace('/<span class="post-b">([^<]*?)<(?=\/)\/span>/', '[b]$1[/b]', $text);
					$text = preg_replace('/<span class="post-u">([^<]*?)<(?=\/)\/span>/', '[u]$1[/u]', $text);
					$text = preg_replace('/<span class="post-i">([^<]*?)<(?=\/)\/span>/', '[i]$1[/i]', $text);
					$text = preg_replace('/<span class="post-s">([^<]*?)<(?=\/)\/span>/', '[s]$1[/s]', $text);
					$text = preg_replace('/<span style="font-size: ([^<]*?)px; line-height: normal;">([^<]*?)<(?=\/)\/span>/', "[size=\\1]\\2[/size]", $text);
					$text = preg_replace('/<span style="font-family: ([^<]*?);">([^<]*?)<(?=\/)\/span>/', "[font=\"\\1\"]\\2[/font]", $text);
					$text = preg_replace('/<span class="post-align" style="text-align: ([^<]*?);">([^<]*?)<(?=\/)\/span>/', "[align=\\1]\n\\2\n[/align]", $text);
					$text = preg_replace('/<span style="color: ([^<]*?);">([^<]*?)<(?=\/)\/span>/', '[color=$1]$2[/color]', $text);
					$text = preg_replace('/<a href="([^<]*?)" class="postLink">([^<]*?)<(?=\/)\/a>/', '[url=$1]$2[/url]', $text);
					$text = preg_replace('/<div class="sp-body" title="([^<]*?)">([^<]*?)<(?=\/)\/div>([\s\S]*?)<([^<]*?)\/div>/', "[spoiler=\"\\1\"]\n\\2\n[/spoiler]", $text);
					$text = preg_replace('/<div class="sp-body">([^<]*?)<(?=\/)\/div>([\s\S]*?)<([^<]*?)\/div>/', "[spoiler]\n\\1\n[/spoiler]", $text);
					$text = preg_replace('/<div class="q">([^<]*?)<(?=\/)\/div>([^<]*?)<([^<]*?)\/div>/', "[quote]\n\\1\n[/quote]", $text);
					$text = preg_replace('/<div class="q" head="([^<]*?)">([^<]*?)<(?=\/)\/div>([\s\S]*?)<([^<]*?)\/div>/', "[quote=\"\\1\"]\n\\2\n[/quote]", $text);
					$text = preg_replace('/<div class="c-head"><b>([^<]*?)<\/b><\/div>([^<]*?)<div class="c-body">([^<]*?)<(?=\/)\/div>([\s\S]*?)<([^<]*?)\/div>/', "[code]\n\\3\n[/code]", $text);
					$text = preg_replace('/<div style="text-align:([^<]*?)">([^<]*?)<(?=\/)\/div>/', '<div>[align=$1]$2[/align]</div>', $text);
				}

			    // Убираем пустое пространство
				$text = preg_replace('/([\r\n])[\s]+/is', "\\1", $text);
				$text = strip_tags(html_entity_decode($text));
			}
			return $text;
		}

	    if ($message = rutracker($content))
	    {
		    $id = rutracker($content, 'torrent');;

	        $snoopy->submit("http://dl.rutracker.org/forum/dl.php?t=". $id);
		    $torrent = $snoopy->results;
		    $tor = bdecode($torrent);
		    if(count($tor))
		    {
			    //if((array_key_exists('announce-list', $tor)) || $tor['announce'])
			    //{
				    $new_name = md5($torrent);
				    $file = fopen('files/'. $new_name .'.torrent', 'w');
					fputs($file, $torrent);
			        fclose($file);

				    $hidden_form_fields .= '<input type="hidden" name="add_attachment_body" value="0" />';
					$hidden_form_fields .= '<input type="hidden" name="posted_attachments_body" value="0" />';
					$hidden_form_fields .= '<input type="hidden" name="attachment_list[]" value="files/'. $new_name .'.torrent" />';
					$hidden_form_fields .= '<input type="hidden" name="filename_list[]" value="torrent ('. create_date($bb_cfg['post_date_format'], TIMENOW) .')" />';
					$hidden_form_fields .= '<input type="hidden" name="extension_list[]" value="torrent" />';
					$hidden_form_fields .= '<input type="hidden" name="mimetype_list[]" value="application/x-bittorrent" />';
					$hidden_form_fields .= '<input type="hidden" name="filesize_list[]" value="'. filesize('files/'. $new_name .'.torrent') .'" />';
			        $hidden_form_fields .= '<input type="hidden" name="filetime_list[]" value="'. TIMENOW .'" />';
			        $hidden_form_fields .= '<input type="hidden" name="attach_id_list[]" value="" />';
			        $hidden_form_fields .= '<input type="hidden" name="attach_thumbnailsnail_list[]" value="0" />';
		        //}
		    }
	    }
	    $subject = rutracker($content, 'title');
    }
    elseif($_POST['tracker'] == 'pornolab')
    {
	    if (!preg_match("/http:\/\/pornolab.net\/forum\/viewtopic.php\?t=/", $url))
	    {
	    	meta_refresh('', '2');
	    	bb_die("false link<script>alert('false link http://pornolab.net/forum/viewtopic.php?t=xxxx');</script>");
	    }

	    $snoopy = new Snoopy;
		$snoopy->host = "pornolab.net";
		$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
		$snoopy->referer = "http://pornolab.net/";
		$snoopy->rawheaders["Pragma"] = "no-cache";

		$submit_url = "http://pornolab.net/forum/login.php";
		$snoopy->_submit_method = "POST";
		$submit_vars = array (
			'login_username' => "ZerocooL1143", //логин
			'login_password' => "Rsx9j", //пароль
			'login' => $lang['LOGIN'],
		);
		$snoopy->submit($submit_url, $submit_vars);

	    $snoopy->_httpmethod = "GET";
	    $snoopy->fetch($url);
	    $content = iconv('windows-1251', 'UTF-8', $snoopy->results);
	    $pos = strpos($content, '<form method="post" action="thx.php">');
		$content = substr($content, 0, $pos);

	    if (!$content)
	    {
	    	meta_refresh('', '2');
	    	bb_die('false content');
	    }

	    function pornolab($text, $mode=false)
		{

			if($mode == 'title')
			{
				preg_match_all ("#<h1 class=\"maintitle\"><a href=\".*?\">([\s\S]*?)</a></h1>#", $text, $source, PREG_SET_ORDER);
			    $text = $source[0][1];
				$text = str_replace('<wbr>', '', $text);
		    }
		    elseif($mode == 'torrent')
		    {
		    	preg_match_all ("#<a href=\"dl.php\?t=([\s\S]*?)\" class#", $text, $source, PREG_SET_ORDER);
			    $text = $source[0][1];
		    }
		    else
		    {
				$pos = strpos($text, '<div class="post_body"');
				$text = substr($text, $pos);
				$pos = strpos($text, '<div class="clear"></div>');
				$text = substr($text, 0, $pos);
				$text = preg_replace('/<div class="post_body" id=".*?">/', '', $text);

				$text = preg_replace('#<img class="smile" src=".*?" align="absmiddle" border="0" />#', '', $text);
				$text = preg_replace('#\n<h3 class="sp-title">.*?</h3>#', '', $text);
				$text = str_replace('<div class="q-wrap">', '', $text);
				$text = str_replace('<div class="sp-wrap">', '', $text);
				$text = str_replace('<div class="c-wrap">', '', $text);
				$text = preg_replace('#<a name=".*?"></a>#', '', $text);
				$text = preg_replace('#<a class="postLink-name" href=".*?">([\s\S]*?)</a>#', '$1', $text);
				$text = str_replace('<span class="post-hr">-</span>', "\n[hr]\n", $text);
                $text = preg_replace('#<pre class="post-pre">([\s\S]*?)</pre>#', '$1', $text);
				$text = preg_replace('#<div style="margin-.*?">([\s\S]*?)</div>#', '$1', $text);
				$text = preg_replace('/<var class="postImg" title="(.*?)">&#10;<\/var>/', '[img]$1[/img]', $text);
				$text = preg_replace('/<var class="postImg postImgAligned img-(.*?)" title="(.*?)">&#10;<\/var>/', "[img=\\1]\\2[/img]\n", $text);
				$text = str_replace('<span class="post-br"><br /></span>', "\n\n", $text);

				$text = preg_replace('/<br.*?>/', '', $text);
				$text = preg_replace('/<ul type="(.*?)">/', '[list=$1]', $text);
				$text = str_replace('<ul>', '[list]', $text);
				$text = str_replace('</ul>', '[/list]', $text);
				$text = str_replace('<li>', "\n[*]", $text);
				$text = str_replace('</li>', '', $text);

                $text = str_replace('&#039;', "'", $text);
				$text = str_replace('&nbsp;', ' ', $text);
				$text = str_replace('&gt;', '>', $text);
				$text = str_replace('&lt;', '<', $text);

				for ($i=0; $i<=20; $i++)
				{
					$text = preg_replace('/<span class="post-b">([^<]*?)<(?=\/)\/span>/', '[b]$1[/b]', $text);
					$text = preg_replace('/<span class="post-u">([^<]*?)<(?=\/)\/span>/', '[u]$1[/u]', $text);
					$text = preg_replace('/<span class="post-i">([^<]*?)<(?=\/)\/span>/', '[i]$1[/i]', $text);
					$text = preg_replace('/<span class="post-s">([^<]*?)<(?=\/)\/span>/', '[s]$1[/s]', $text);
					$text = preg_replace('/<span style="font-size: ([^<]*?)px; line-height: normal;">([^<]*?)<(?=\/)\/span>/', "[size=\\1]\\2[/size]", $text);
					$text = preg_replace('/<span style="font-family: ([^<]*?);">([^<]*?)<(?=\/)\/span>/', "[font=\"\\1\"]\\2[/font]", $text);
					$text = preg_replace('/<span class="post-align" style="text-align: ([^<]*?);">([^<]*?)<(?=\/)\/span>/', "[align=\\1]\n\\2\n[/align]", $text);
					$text = preg_replace('/<span style="color: ([^<]*?);">([^<]*?)<(?=\/)\/span>/', '[color=$1]$2[/color]', $text);
					$text = preg_replace('/<a href="([^<]*?)" class="postLink">([^<]*?)<(?=\/)\/a>/', '[url=$1]$2[/url]', $text);
					$text = preg_replace('/<div class="sp-body" title="([^<]*?)">([^<]*?)<(?=\/)\/div>([\s\S]*?)<([^<]*?)\/div>/', "[spoiler=\"\\1\"]\n\\2\n[/spoiler]", $text);
					$text = preg_replace('/<div class="sp-body">([^<]*?)<(?=\/)\/div>([\s\S]*?)<([^<]*?)\/div>/', "[spoiler]\n\\1\n[/spoiler]", $text);
					$text = preg_replace('/<div class="q">([^<]*?)<(?=\/)\/div>([^<]*?)<([^<]*?)\/div>/', "[quote]\n\\1\n[/quote]", $text);
					$text = preg_replace('/<div class="q" head="([^<]*?)">([^<]*?)<(?=\/)\/div>([\s\S]*?)<([^<]*?)\/div>/', "[quote=\"\\1\"]\n\\2\n[/quote]", $text);
					$text = preg_replace('/<div class="c-head"><b>([^<]*?)<\/b><\/div>([^<]*?)<div class="c-body">([^<]*?)<(?=\/)\/div>([\s\S]*?)<([^<]*?)\/div>/', "[code]\n\\3\n[/code]", $text);
					$text = preg_replace('/<div style="text-align:([^<]*?)">([^<]*?)<(?=\/)\/div>/', '<div>[align=$1]$2[/align]</div>', $text);
				}

			    // Убираем пустое пространство
				$text = preg_replace('/([\r\n])[\s]+/is', "\\1", $text);
				$text = strip_tags(html_entity_decode($text));
			}
			return $text;
		}

	    if ($message = pornolab($content))
	    {
		    $id = pornolab($content, 'torrent');;

	        $snoopy->submit("http://pornolab.net/forum/dl.php?t=". $id);
		    $torrent = $snoopy->results;
		    $tor = bdecode($torrent);
		    if(count($tor))
		    {
			    $new_name = md5($torrent);
			    $file = fopen('files/'. $new_name .'.torrent', 'w');
				fputs($file, $torrent);
		        fclose($file);

			    $hidden_form_fields .= '<input type="hidden" name="add_attachment_body" value="0" />';
				$hidden_form_fields .= '<input type="hidden" name="posted_attachments_body" value="0" />';
				$hidden_form_fields .= '<input type="hidden" name="attachment_list[]" value="files/'. $new_name .'.torrent" />';
				$hidden_form_fields .= '<input type="hidden" name="filename_list[]" value="torrent ('. create_date($bb_cfg['post_date_format'], TIMENOW) .')" />';
				$hidden_form_fields .= '<input type="hidden" name="extension_list[]" value="torrent" />';
				$hidden_form_fields .= '<input type="hidden" name="mimetype_list[]" value="application/x-bittorrent" />';
				$hidden_form_fields .= '<input type="hidden" name="filesize_list[]" value="'. filesize('files/'. $new_name .'.torrent') .'" />';
		        $hidden_form_fields .= '<input type="hidden" name="filetime_list[]" value="'. TIMENOW .'" />';
		        $hidden_form_fields .= '<input type="hidden" name="attach_id_list[]" value="" />';
		        $hidden_form_fields .= '<input type="hidden" name="attach_thumbnailsnail_list[]" value="0" />';
	        }
	    }
	    $subject = pornolab($content, 'title');
    }
    elseif($_POST['tracker'] == 'tapochek')
    {
        if (!preg_match("/http:\/\/tapochek.net\/viewtopic.php\?t=/", $url))
	    {
	    	meta_refresh('', '2');
	    	bb_die("false link<script>alert('false link http://tapochek.net/viewtopic.php?t=xxxx');</script>");
	    }

	    $snoopy = new Snoopy;
		$snoopy->host = "tapochek.net";
		$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
		$snoopy->referer = "http://tapochek.net/";
		$snoopy->rawheaders["Pragma"] = "no-cache";

		$snoopy->cookies['bb_data'] = urldecode('a%3A3%3A%7Bs%3A2%3A%22uk%22%3BN%3Bs%3A3%3A%22uid%22%3Bi%3A96532%3Bs%3A3%3A%22sid%22%3Bs%3A20%3A%227NB5SUSC3NhrHxY46DJt%22%3B%7D'); //суда прописать куки (как их узнать сомтреть в гугле)

	    $snoopy->_httpmethod = "GET";
	    $snoopy->fetch($url);
	    $content = iconv('windows-1251', 'UTF-8', $snoopy->results);
	    $pos = strpos($content, '<p><img src="images/icon_dn.gif"');
		$content = substr($content, 0, $pos);

	    if (!$content)
	    {
	    	meta_refresh('', '2');
	    	bb_die('false content');
	    }

	    function tapochek($text, $mode=false)
		{
			if($mode == 'title')
			{
				preg_match_all ("#<h1 class=\"maintitle\" style=\"float:left\"><a href=\".*?\">([\s\S]*?)</a></h1>#", $text, $source, PREG_SET_ORDER);
			    $text = $source[0][1];
				$text = str_replace('<wbr>', '', $text);
		    }
		    elseif($mode == 'torrent')
		    {
		    	preg_match_all ("#<th colspan=\"3\" class=\"genmed\">(.*?).torrent</th>[\s\S]*?<a href=\"download.php\?id=(.*?)\" #", $text, $source, PREG_SET_ORDER);
			    $text = $source[0];
		    }
		    else
		    {
				$pos = strpos($text, '<div class="post_body"');
				$text = substr($text, $pos);
				$pos = strpos($text, '<div class="spacer_8"></div>');
				$text = substr($text, 0, $pos);
                $text = str_replace('<div class="post_body">', '', $text);
                $text = str_replace('<wbr>', '', $text);

				//preg_match_all ("#<div class=\"post_body\" id=\".*?\">([\s\S]*?)<div class=\"clear\"></div>#", $text, $source, PREG_SET_ORDER);
			    //$text = $source[0][1];

				$text = preg_replace('/<img class="smile" src=".*?" align="absmiddle" border="0" \/>/', '', $text);
                $text = str_replace('<div class="q-wrap">', '', $text);
				$text = str_replace('<div class="sp-wrap">', '', $text);
				$text = str_replace('<div class="c-wrap">', '', $text);
                $text = str_replace('<div class="clear"></div>', '', $text);

                $text = preg_replace('/<div style="display: none;">.*?<\/div>/', '', $text);

				$text = str_replace('<hr />', "\n[hr]\n", $text);
                $text = preg_replace('/<var class="postImg" title="(.*?)">&#10;<\/var>/', '[img]$1[/img]', $text);
				$text = preg_replace('/<var class="postImg postImgAligned img-(.*?)" title="([\s\S]*?)">&#10;<\/var>/', "[img=\\1]\\2[/img]\n", $text);

				$text = str_replace('<ul>', '[list]', $text);
				$text = str_replace('</ul>', '[/list]', $text);
				$text = str_replace('<li>', "\n[*]", $text);
				$text = str_replace('</li>', '', $text);
				$text = str_replace('<ol type="1">', '[list=1]', $text);
				$text = str_replace('<ol type="a">', '[list=a]', $text);
				$text = str_replace('</ol>', '[/list]', $text);
				$text = str_replace('', "\n", $text);
				$text = str_replace('<div></div>', "\n", $text);
                $text = preg_replace('/<a href="([^<]*?)" rel=".*?"><img src=".*?" \/>&nbsp;<\/a>/', '[thumbnails]$1[/thumbnails]', $text);

                $text = str_replace('<br clear="all" />', "\n[br]\n", $text);
                $text = str_replace('<br />', "\n", $text);

                $text = str_replace('<div', '<span', $text);
                $text = str_replace('</div>', '</span>', $text);
                $text = str_replace('<a', '<span', $text);
                $text = str_replace('</a>', '</span>', $text);

                $text = str_replace('&#039;', "'", $text);
				$text = str_replace('&nbsp;', ' ', $text);
				$text = str_replace('&gt;', '>', $text);
				$text = str_replace('&lt;', '<', $text);

				for ($i=0; $i<=20; $i++)
				{
					$text = preg_replace('/<span style="font-weight: bold;">([^<]*?)<(?=\/)\/span>/', '[b]$1[/b]', $text);
					$text = preg_replace('/<span style="text-decoration: underline;">([^<]*?)<(?=\/)\/span>/', '[u]$1[/u]', $text);
					$text = preg_replace('/<span style="font-style: italic;">([^<]*?)<(?=\/)\/span>/', '[i]$1[/i]', $text);
					$text = preg_replace('/<span style="font-size: ([^<]*?)px; line-height: normal;">([^<]*?)<(?=\/)\/span>/', "[size=\\1]\\2[/size]", $text);
					$text = preg_replace('/<span style="font-family: ([^<]*?)">([^<]*?)<(?=\/)\/span>/', "[font=\"\\1\"]\\2[/font]", $text);
					$text = preg_replace('/<span style="text-align: ([^<]*?);">([^<]*?)<(?=\/)\/span>/', "[align=\\1]\n\\2\n[/align]", $text);
					$text = preg_replace('/<span style="color: ([^<]*?);">([^<]*?)<(?=\/)\/span>/', '[color=$1]$2[/color]', $text);

					$text = preg_replace('/<span href="([^<]*?)" class="postLink">([^<]*?)<(?=\/)\/span>/', '[url=$1]$2[/url]', $text);
					$text = preg_replace('/<span class="sp-body" title="([^<]*?)">([^<]*?)<(?=\/)\/span>([\s\S]*?)<([^<]*?)\/span>/', "[spoiler=\"\\1\"]\n\\2\n[/spoiler]", $text);
					$text = preg_replace('/<span class="sp-body">([^<]*?)<(?=\/)\/span>([\s\S]*?)<([^<]*?)\/span>/', "[spoiler]\n\\1\n[/spoiler]", $text);
					$text = preg_replace('/<span class="q">([^<]*?)<(?=\/)\/span>([^<]*?)<([^<]*?)\/span>/', "[quote]\n\\1\n[/quote]", $text);
					$text = preg_replace('/<span class="q" head="([^<]*?)">([^<]*?)<(?=\/)\/span>([\s\S]*?)<([^<]*?)\/span>/', "[quote=\"\\1\"]\n\\2\n[/quote]", $text);
					$text = preg_replace('/<span class="c-head"><b>([^<]*?)<\/b><\/span>([^<]*?)<span class="c-body">([^<]*?)<(?=\/)\/span>([\s\S]*?)<([^<]*?)\/span>/', "[code]\n\\3\n[/code]", $text);
				}

			    // Убираем пустое пространство
				$text = preg_replace('/([\r\n])[\s]+/is', "\\1", $text);
				$text = strip_tags(html_entity_decode($text));
			}
			return $text;
		}

	    if ($message = tapochek($content))
	    {
		    $tor = tapochek($content, 'torrent');;
            $id = $tor[2];
            $name = $tor[1];

	        $snoopy->submit("http://tapochek.net/download.php?id=". $id);
		    $torrent = $snoopy->results;
		    $tor = bdecode($torrent);
		    if(count($tor))
		    {
			    $new_name = md5($torrent);
			    $file = fopen('files/'. $new_name .'.torrent', 'w');
				fputs($file, $torrent);
		        fclose($file);

			    $hidden_form_fields .= '<input type="hidden" name="add_attachment_body" value="0" />';
				$hidden_form_fields .= '<input type="hidden" name="posted_attachments_body" value="0" />';
				$hidden_form_fields .= '<input type="hidden" name="attachment_list[]" value="files/'. $new_name .'.torrent" />';
				$hidden_form_fields .= '<input type="hidden" name="filename_list[]" value="'. $name .'" />';
				$hidden_form_fields .= '<input type="hidden" name="extension_list[]" value="torrent" />';
				$hidden_form_fields .= '<input type="hidden" name="mimetype_list[]" value="application/x-bittorrent" />';
				$hidden_form_fields .= '<input type="hidden" name="filesize_list[]" value="'. filesize('files/'. $new_name .'.torrent') .'" />';
		        $hidden_form_fields .= '<input type="hidden" name="filetime_list[]" value="'. TIMENOW .'" />';
		        $hidden_form_fields .= '<input type="hidden" name="attach_id_list[]" value="" />';
		        $hidden_form_fields .= '<input type="hidden" name="attach_thumbnailsnail_list[]" value="0" />';
            }
        }
	    $subject = tapochek($content, 'title');
    }
    elseif($_POST['tracker'] == 'rustorka')
    {
        if (!preg_match("/http:\/\/rustorka.com\/forum\/viewtopic.php\?t=/", $url))
	    {
	    	meta_refresh('', '2');
	    	bb_die("false link<script>alert('false link http://rustorka.com/forum/viewtopic.php?t=xxxx');</script>");
	    }

	    $snoopy = new Snoopy;
		$snoopy->host = "rustorka.com";
		$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
		$snoopy->referer = "http://rustorka.com/";
		$snoopy->rawheaders["Pragma"] = "no-cache";

		$submit_url = "http://rustorka.com/forum/login.php";
		$snoopy->_submit_method = "POST";
		$submit_vars = array (
			'login_username' => "Marison", //логин
			'login_password' => "kamelot", //пароль
			'login' => $lang['LOGIN'],
		);
		$snoopy->submit($submit_url, $submit_vars);

	    $snoopy->_httpmethod = "GET";
	    $snoopy->fetch($url);
	    $content = iconv('windows-1251', 'UTF-8', $snoopy->results);
	    $pos = strpos($content, '<table width="100%" border="0" align="center">');
		$content = substr($content, 0, $pos);

	    if (!$content)
	    {
	    	meta_refresh('', '2');
	    	bb_die('false content');
	    }

	    function rustorka($text, $mode=false)
		{
			if($mode == 'title')
			{
				preg_match_all ("#<h1 class=\"maintitle\"><a href=\".*?\">([\s\S]*?)</a></h1>#", $text, $source, PREG_SET_ORDER);
			    $text = $source[0][1];
				$text = str_replace('<wbr>', '', $text);
		    }
		    elseif($mode == 'torrent')
		    {
		    	preg_match_all ("#<th colspan=\"3\" class=\"genmed\">(.*?).torrent</th>[\s\S]*?<a href=\"download.php\?id=(.*?)\" #", $text, $source, PREG_SET_ORDER);
			    $text = $source[0];
		    }
		    else
		    {
				$pos = strpos($text, '<div class="post_body"');
				$text = substr($text, $pos);
				$pos = strpos($text, '<div class="spacer_8"></div>');
				$text = substr($text, 0, $pos);
                $text = preg_replace('/<div class="post_body">/', '', $text);
                $text = str_replace('<wbr>', '', $text);
                $text = preg_replace('/([\r\n])[\s]+/is', "\\1", $text);
				//preg_match_all ("#<div class=\"post_body\" id=\".*?\">([\s\S]*?)<div class=\"clear\"></div>#", $text, $source, PREG_SET_ORDER);
			    //$text = $source[0][1];

				$text = preg_replace('/<img class="smile" src=".*?" align="absmiddle" border="0" \/>/', '', $text);
                $text = str_replace('<div class="clear"></div>', '', $text);
                $text = preg_replace('/<!--\/.*?-->/', '', $text);
				$text = str_replace('<hr />', "\n[hr]\n", $text);
                $text = preg_replace('/<div class="postImg-wrap" style=".*?" align="center"><img src="(.*?)" id="postImgAligned" class="postImg" alt="pic" \/><\/div>/', "[align=center][img]\\1[/img][/align]\n", $text);
				$text = preg_replace('/<div class="postImg-wrap" style=".*?" align="(.*?)"><img src="(.*?)" id="postImgAligned" class="postImg" alt="pic" \/><\/div>/', "[img=\\1]\\2[/img]\n", $text);
				$text = preg_replace('/<img src="(.*?)" id="postImg" class="postImg" align="absmiddle" hspace="0" vspace="4" alt="pic" \/>/', '[img]$1[/img]', $text);
				$text = preg_replace('/<a href="([^<]*?)" rel=".*?"><img src=".*?" \/>&nbsp;<\/a>/', '[thumbnails]$1[/thumbnails]', $text);

				$text = str_replace('<ul>', '[list]', $text);
				$text = str_replace('</ul>', '[/list]', $text);
				$text = str_replace('<li>', "\n[*]", $text);
				$text = str_replace('</li>', '', $text);
				$text = str_replace('<br /><br />', "\n", $text);
				$text = str_replace('<br clear="all" />', "\n[br]\n", $text);
				$text = str_replace('<div></div>', "\n", $text);
				$text = str_replace('<div', '<span', $text);
                $text = str_replace('</div>', '</span>', $text);
                $text = str_replace('<a', '<span', $text);
                $text = str_replace('</a>', '</span>', $text);

                $text = str_replace('&#039;', "'", $text);
				$text = str_replace('&nbsp;', ' ', $text);
				$text = str_replace('&gt;', '>', $text);
				$text = str_replace('&lt;', '<', $text);

				for ($i=0; $i<=20; $i++)
				{
					$text = preg_replace('/<span style="font-weight: bold;">([^<]*?)<(?=\/)\/span>/', '[b]$1[/b]', $text);
					$text = preg_replace('/<span style="text-decoration: underline;">([^<]*?)<(?=\/)\/span>/', '[u]$1[/u]', $text);
					$text = preg_replace('/<span style="font-style: italic;">([^<]*?)<(?=\/)\/span>/', '[i]$1[/i]', $text);
					$text = preg_replace('/<span style="font-size: ([^<]*?)px; line-height: normal;">([^<]*?)<(?=\/)\/span>/', "[size=\\1]\\2[/size]", $text);
					$text = preg_replace('/<span style="font-family: ([^<]*?)">([^<]*?)<(?=\/)\/span>/', "[font=\"\\1\"]\\2[/font]", $text);
					$text = preg_replace('/<span style="text-align: ([^<]*?);">([^<]*?)<(?=\/)\/span>/', "[align=\\1]\n\\2\n[/align]", $text);
					$text = preg_replace('/<span style="color: ([^<]*?);">([^<]*?)<(?=\/)\/span>/', '[color=$1]$2[/color]', $text);

					$text = preg_replace('/<span href="([^<]*?)" class="postLink">([^<]*?)<(?=\/)\/span>/', '[url=$1]$2[/url]', $text);
					$text = preg_replace('/<p class="q_head"><b>.*?<\/b><\/p>[\s\S]*?<div class="q">([^<]*?)<(?=\/)\/div><!--\/q-->/', "[quote]\n\\1\n[/quote]", $text);
					$text = preg_replace('/<p class="q_head"><b>(.*?)<\/b>.*?<\/p>[\s\S]*?<div class="q">([^<]*?)<(?=\/)\/div><!--\/q-->/', "[quote=\"\\1\"]\n\\2\n[/quote]", $text);
					$text = preg_replace('/<span class="code">([^<]*?)<(?=\/)\/span>/', "[code]\n\\1\n[/code]", $text);
					$text = preg_replace('/<span class="spoiler-wrap.*? clickable">([^<]*?)<\/span>[^<]*?<span class="spoiler-body">([^<]*?)<(?=\/)\/span>[^<]*?<(?=\/)\/span>/', "[spoiler=\"\\1\"]\n\\2\n[/spoiler]", $text);
			    }

			    // Убираем пустое пространство
				$text = preg_replace('/([\r\n])[\s]+/is', "\\1", $text);
				$text = strip_tags(html_entity_decode($text));
			}
			return $text;
		}

	    if ($message = rustorka($content))
	    {
		    $tor = rustorka($content, 'torrent');;
            $id = $tor[2];
            $name = $tor[1];

	        $snoopy->submit("http://rustorka.com/forum/download.php?id=". $id);
		    $torrent = $snoopy->results;
		    $tor = bdecode($torrent);
		    if(count($tor))
		    {
			    $new_name = md5($torrent);
			    $file = fopen('files/'. $new_name .'.torrent', 'w');
				fputs($file, $torrent);
		        fclose($file);

			    $hidden_form_fields .= '<input type="hidden" name="add_attachment_body" value="0" />';
				$hidden_form_fields .= '<input type="hidden" name="posted_attachments_body" value="0" />';
				$hidden_form_fields .= '<input type="hidden" name="attachment_list[]" value="files/'. $new_name .'.torrent" />';
				$hidden_form_fields .= '<input type="hidden" name="filename_list[]" value="'. $name .'" />';
				$hidden_form_fields .= '<input type="hidden" name="extension_list[]" value="torrent" />';
				$hidden_form_fields .= '<input type="hidden" name="mimetype_list[]" value="application/x-bittorrent" />';
				$hidden_form_fields .= '<input type="hidden" name="filesize_list[]" value="'. filesize('files/'. $new_name .'.torrent') .'" />';
		        $hidden_form_fields .= '<input type="hidden" name="filetime_list[]" value="'. TIMENOW .'" />';
		        $hidden_form_fields .= '<input type="hidden" name="attach_id_list[]" value="" />';
		        $hidden_form_fields .= '<input type="hidden" name="attach_thumbnailsnail_list[]" value="0" />';
            }
	    }
	    $subject = rustorka($content, 'title');
    }
    elseif($_POST['tracker'] == 'rutor')
    {
    	if (!preg_match("/http:\/\/rutor.org\/torrent\//", $url))
	    {
	    	meta_refresh('', '2');
	    	bb_die("false link<script>alert('false link http://rutor.org/torrent/xxxx');</script>");
	    }

        $snoopy = new Snoopy;
		$snoopy->host = "rutor.org";
		$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
		$snoopy->referer = "http://rutor.org/";
		$snoopy->rawheaders["Pragma"] = "no-cache";
	    $snoopy->_httpmethod = "GET";
	    $snoopy->fetch($url);
	    $content = $snoopy->results;
	    //$content = iconv('windows-1251', 'UTF-8', $content);
	    $pos = strpos($content, '<td class="header"');
		$content = substr($content, 0, $pos);
  	    if (!$content)
	    {
	    	meta_refresh('', '2');
	    	bb_die('false content');
	    }

	    function rutor($text, $mode=false)
		{
			if($mode == 'title')
			{
				preg_match_all ("#<h1>([\s\S]*?)</h1>#", $text, $source, PREG_SET_ORDER);
			    $text = $source[0][1];
		    }
		    elseif($mode == 'torrent')
		    {
		    	preg_match_all ("#<a href=\"/download/([\s\S]*?)\"><img src=\"http://s.rutor.org/t/down.png\"> .*? ([\s\S]*?).torrent</a>#", $text, $source, PREG_SET_ORDER);
			    $text = $source[0];
		    }
		    else
		    {
				preg_match_all ("#<tr><td style=\"vertical-align:top;\"></td><td>([\s\S]*?)</td></tr>#si", $text, $source, PREG_SET_ORDER);
			    $text = $source[0][1];

				$text = preg_replace('/<br.*?>/', "", $text);
                $text = preg_replace('/<a href="\/tag\/.*?" target="_blank">([\s\S]*?)<\/a>/', '$1', $text);
                $text = preg_replace('/<div class="hidewrap"><div class="hidehead" onclick="hideshow.*?">([\s\S]*?)<\/div><div class="hidebody"><\/div><textarea class="hidearea">([\s\S]*?)<\/textarea><\/div>/', "[spoiler=\"\\1\"]\\2[/spoiler]", $text);
                $text = preg_replace('/<a href="([\s\S]*?)" target="_blank">([\s\S]*?)<\/a>/', '[url=$1]$2[/url]', $text);
                $text = preg_replace('/<img src="(.*?)" style="float:(.*?);" \/>/', '[img=$2]$1[/img]', $text);
                $text = preg_replace('/<img src="([\s\S]*?)" \/>/', '[img]$1[/img]', $text);

                $text = str_replace('<center>', '[align=center]', $text);
				$text = str_replace('</center>', '[/align]', $text);
                $text = str_replace('<hr />', '[hr]', $text);

				$text = str_replace('&#039;', "'", $text);
				$text = str_replace('&nbsp;', ' ', $text);
				$text = str_replace('&gt;', '>', $text);
				$text = str_replace('&lt;', '<', $text);

				for ($i=0; $i<=20; $i++)
				{
					$text = preg_replace('/<b>([^<]*?)<(?=\/)\/b>/', '[b]$1[/b]', $text);
					$text = preg_replace('/<u>([^<]*?)<(?=\/)\/u>/', '[u]$1[/u]', $text);
					$text = preg_replace('/<i>([^<]*?)<(?=\/)\/i>/', '[i]$1[/i]', $text);
					$text = preg_replace('/<s>([^<]*?)<(?=\/)\/s>/', '[s]$1[/s]', $text);
					$text = preg_replace('/<font size="([^<]*?)">([^<]*?)<(?=\/)\/font>/', "[size=2\\1]\\2[/size]", $text);
					$text = preg_replace('/<span style="color:([^<]*?);">([^<]*?)<(?=\/)\/span>/', '[color=$1]$2[/color]', $text);
				    $text = preg_replace('/<span style="font-family:([^<]*?);">([^<]*?)<(?=\/)\/span>/', '[font=$1]$2[/font]', $text);
				}
				$text = strip_tags(html_entity_decode($text));
			}
			return $text;
		}

	    if ($message = rutor($content))
	    {
		    $tor = rutor($content, 'torrent');
            $name = $tor[2];
            $id = $tor[1];

		    $torrent = file_get_contents("http://rutor.org/download/". $id);
		    $new_name = md5($torrent);
		    $file = fopen('files/'. $new_name .'.torrent', 'w');
			fputs($file, $torrent);
	        fclose($file);

		    $hidden_form_fields .= '<input type="hidden" name="add_attachment_body" value="0" />';
			$hidden_form_fields .= '<input type="hidden" name="posted_attachments_body" value="0" />';
			$hidden_form_fields .= '<input type="hidden" name="attachment_list[]" value="files/'. $new_name .'.torrent" />';
			$hidden_form_fields .= '<input type="hidden" name="filename_list[]" value="'. $name .'" />';
			$hidden_form_fields .= '<input type="hidden" name="extension_list[]" value="torrent" />';
			$hidden_form_fields .= '<input type="hidden" name="mimetype_list[]" value="application/x-bittorrent" />';
			$hidden_form_fields .= '<input type="hidden" name="filesize_list[]" value="'. filesize('files/'. $new_name .'.torrent') .'" />';
	        $hidden_form_fields .= '<input type="hidden" name="filetime_list[]" value="'. TIMENOW .'" />';
	        $hidden_form_fields .= '<input type="hidden" name="attach_id_list[]" value="" />';
	        $hidden_form_fields .= '<input type="hidden" name="attach_thumbnailsnail_list[]" value="0" />';

	    }
	    $subject = rutor($content, 'title');

    }
    elseif($_POST['tracker'] == 'anidub')
    {
        if (!preg_match("/http:\/\/tr.anidub.com\/details.php\?id=/", $url))
	    {
	    	meta_refresh('', '2');
	    	bb_die("false link<script>alert('false link http://tr.anidub.com/details.php?id=xxxx');</script>");
	    }

	    $snoopy = new Snoopy;
		$snoopy->host = "tr.anidub.com";
		$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
		$snoopy->referer = "http://tr.anidub.com/";
		$snoopy->rawheaders["Pragma"] = "no-cache";

		$submit_url = "http://tr.anidub.com/takelogin.php";
		$snoopy->_submit_method = "POST";
		$submit_vars = array (
			'username' => "Amigoaktau",
			'password' => "123321",
		);
		$snoopy->submit($submit_url, $submit_vars);

	    $snoopy->_httpmethod = "GET";
	    $snoopy->fetch($url);
	    $content = iconv('windows-1251', 'UTF-8', $snoopy->results);
	    $content = preg_replace('/([\r\n])[\s]+/is', "\\1", $content);
	    $pos = strpos($content, '<table width="100%" border="1" cellspacing="0" cellpadding="5">');
	    $content = substr($content, $pos);
	    $pos = strpos($content, '<form action="thanks.php" method="post" id="thanksForm">');
		$content = substr($content, 0, $pos);

	    if (!$content)
	    {
	    	meta_refresh('', '2');
	    	bb_die('false content');
	    }

        function anidub($text, $mode=false)
		{
			if($mode == 'title')
			{
				preg_match_all ("#<b>([\s\S]*?)</b>#", $text, $source, PREG_SET_ORDER);
			    $text = $source[0][1];
		    }
		    elseif($mode == 'torrent')
		    {
		    	preg_match_all ("#<a href=\"download.php\?id=(.*?)&amp;name=(.*?).torrent\">#", $text, $source, PREG_SET_ORDER);
			    $text = $source[0];
		    }
		    else
		    {
				preg_match_all ("#</a><br></a><br>([\s\S]*?)<br></td></tr><tr>#", $text, $source, PREG_SET_ORDER);
				preg_match_all ('/<a href="viewallimage.php\?pic=(.*?)">/', $text, $pic, PREG_SET_ORDER);
			    $poster = ($pic[0][1]) ? "[img=right]". $pic[0][1] ."[/img]\n\n" : "";
			    $text = $poster . $source[0][1];

                $text = str_replace('<a class=\'spoiler_title_c sp-pic_plus_no_c\' width=\'100%\'>', '<a class=spoiler_title>', $text);
                $text = str_replace('<a class=spoiler_title><b>', '<a class=spoiler_title>', $text);
                $text = str_replace('<a class=spoiler_title><b>', '<a class=spoiler_title>', $text);
                $text = preg_replace('/<a class=spoiler_title><.*?>(.*?)<.*?><\/b>/', "<a class=spoiler_title>\\1", $text);

                $text = str_replace('<br />', '', $text);
                $text = preg_replace('/<img class="linked-image" src="(.*?)".*?\/>/', "[img]\\1[/img]", $text);
                $text = preg_replace('/<img border="0" src=".*?">/', '', $text);

                $text = str_replace('&#039;', "'", $text);
				$text = str_replace('&nbsp;', ' ', $text);
				$text = str_replace('&gt;', '>', $text);
				$text = str_replace('&lt;', '<', $text);

				for ($i=0; $i<=20; $i++)
				{
					$text = preg_replace('/<b>([^<]*?)<(?=\/)\/b>/', '[b]$1[/b]', $text);
					$text = preg_replace('/<u>([^<]*?)<(?=\/)\/u>/', '[u]$1[/u]', $text);
					$text = preg_replace('/<i>([^<]*?)<(?=\/)\/i>/', '[i]$1[/i]', $text);
					$text = preg_replace('/<s>([^<]*?)<(?=\/)\/s>/', '[s]$1[/s]', $text);

					$text = preg_replace('/<font style="font-size: ([^<]*?)pt">([^<]*?)<(?=\/)\/font>/', "[size=\\1]\\2[/size]", $text);
					$text = preg_replace('/<span style="font-family: ([^<]*?);">([^<]*?)<(?=\/)\/span>/', "[font=\"\\1\"]\\2[/font]", $text);
					$text = preg_replace('/<span class="post-align" style="text-align: ([^<]*?);">([^<]*?)<(?=\/)\/span>/', "[align=\\1]\\2[/align]", $text);
					$text = preg_replace('/<span style="color: ([^<]*?)">([^<]*?)<(?=\/)\/span>/', '[color=$1]$2[/color]', $text);

					$text = preg_replace('/<a href="([^<]*?)" title=".*?">([^<]*?)<(?=\/)\/a>/', '[url=$1]$2[/url]', $text);
                    $text = preg_replace('/<a class=spoiler_title>(.*?)<\/a><div class=\'spoiler\'>([\s\S]*?)<(?=\/)\/div>/', "[spoiler=\"\\1\"]\\2[/spoiler]", $text);
                }
                $text = str_replace('</b>', '', $text);
                $text = str_replace('<br>', '', $text);
                $text = str_replace('</td></tr><tr>', '', $text);
                $text = preg_replace('/<td valign=middle align=right>(.*?)<\/td><td>/', "\n\n\\1: ", $text);
				$text = strip_tags(html_entity_decode($text));
			}
			return $text;
		}

	    if ($message = anidub($content))
	    {
		    $tor = anidub($content, 'torrent');
            $name = $tor[2];
            $id = $tor[1];

	        $snoopy->submit("http://tr.anidub.com/download.php?id=". $id ."&name=". $name .".torrent");
		    $torrent = $snoopy->results;
		    $tor = bdecode($torrent);
		    if(count($tor))
		    {
			    $new_name = md5($torrent);
			    $file = fopen('files/'. $new_name .'.torrent', 'w');
				fputs($file, $torrent);
		        fclose($file);

			    $hidden_form_fields .= '<input type="hidden" name="add_attachment_body" value="0" />';
				$hidden_form_fields .= '<input type="hidden" name="posted_attachments_body" value="0" />';
				$hidden_form_fields .= '<input type="hidden" name="attachment_list[]" value="files/'. $new_name .'.torrent" />';
				$hidden_form_fields .= '<input type="hidden" name="filename_list[]" value="'. urldecode($name) .'" />';
				$hidden_form_fields .= '<input type="hidden" name="extension_list[]" value="torrent" />';
				$hidden_form_fields .= '<input type="hidden" name="mimetype_list[]" value="application/x-bittorrent" />';
				$hidden_form_fields .= '<input type="hidden" name="filesize_list[]" value="'. filesize('files/'. $new_name .'.torrent') .'" />';
		        $hidden_form_fields .= '<input type="hidden" name="filetime_list[]" value="'. TIMENOW .'" />';
		        $hidden_form_fields .= '<input type="hidden" name="attach_id_list[]" value="" />';
		        $hidden_form_fields .= '<input type="hidden" name="attach_thumbnailsnail_list[]" value="0" />';
	        }
	    }
	    $subject = anidub($content, 'title');
    }
    elseif($_POST['tracker'] == 'tfile')
    {
        if (!preg_match("/http:\/\/tfile.ru\/forum\/viewtopic.php\?t=/", $url))
	    {
	    	meta_refresh('', '2');
	    	bb_die("false link<script>alert('false link http://tfile.ru/forum/viewtopic.php?t=xxxx');</script>");
	    }

        $content = file_get_contents($url);
	    $content = iconv('windows-1251', 'UTF-8', $content);
	    $pos = strpos($content, '<a href="/pages/');
		$content = substr($content, 0, $pos);
  	    if (!$content)
	    {
	    	meta_refresh('', '2');
	    	bb_die('false content');
	    }

	    function tfile($text, $mode=false)
		{
			if($mode == 'title')
			{
				preg_match_all ("#<h1><a href=\"/forum/viewtopic.php.*?\">([\s\S]*?)</a></h1>#", $text, $source, PREG_SET_ORDER);
			    $text = $source[0][1];
		    }
		    elseif($mode == 'torrent')
		    {
		    	preg_match_all ("#<a href=\"download.php\?id=([\s\S]*?)\&uk=1111111111\" class=\"bDownload button\">#", $text, $source, PREG_SET_ORDER);
			    $text = $source[0][1];
		    }
		    else
		    {
				preg_match_all ("#<div class=\"pT\">([\s\S]*?)</td>#si", $text, $source, PREG_SET_ORDER);
			    $text = $source[0][1];

                $text = preg_replace('/<br.*?>/', "", $text);
                $text = preg_replace('/<a href="\/tag\/.*?" target="_blank">([\s\S]*?)<\/a>/', '$1', $text);
                $text = preg_replace('/<div class="hidewrap"><div class="hidehead" onclick="hideshow.*?">([\s\S]*?)<\/div><div class="hidebody"><\/div><textarea class="hidearea">([\s\S]*?)<\/textarea><\/div>/', "[spoiler=\"\\1\"]\\2[/spoiler]", $text);
                $text = preg_replace('/<a href="(.*?)" target="_blank">(.*?)<\/a>/', '[url=$1]$2[/url]', $text);
                $text = preg_replace('/<img src="([^<]*?)" class="postImgAligned"\/>/', "\n[img=right]\\1[/img]\n", $text);
                $text = preg_replace('/<img src="([^<]*?)"\/>/', '[img]$1[/img]', $text);

                $text = preg_replace('/<h2 style=".*?">([\s\S]*?)<\/h2>/', "[size=24][align=center]\\1[/align][/size]\n", $text);

                $text = str_replace('<center>', '[align=center]', $text);
				$text = str_replace('</center>', '[/align]', $text);
                $text = str_replace('<i>', '[i]', $text);
                $text = str_replace('</i>', '[/i]', $text);
                $text = str_replace('<hr>', '[hr]', $text);
                $text = str_replace('<a href="#" class="splink" onclick="return spoiler(this)"><b></b>', '', $text);
                $text = preg_replace('/<div>([\s\S]*?)<\/div>/', '$1', $text);

                $text = preg_replace('/<object .*? value="(.*?)".*?<\/object>/', '[youtube]$1[/youtube]', $text);
                $text = str_replace('youtube.com/v/', 'youtube.com/watch?v=', $text);

                $text = str_replace('&#039;', "'", $text);
				$text = str_replace('&nbsp;', ' ', $text);
				$text = str_replace('&gt;', '>', $text);
				$text = str_replace('&lt;', '<', $text);

				for ($i=0; $i<=20; $i++)
				{
					$text = preg_replace('/<b.*?>([^<]*?)<(?=\/)\/b>/', '[b]$1[/b]', $text);
					$text = preg_replace('/<u>([^<]*?)<(?=\/)\/u>/', '[u]$1[/u]', $text);

					$text = preg_replace('/<s>([^<]*?)<(?=\/)\/s>/', '[s]$1[/s]', $text);
					$text = preg_replace('/<font size="([^<]*?)">([^<]*?)<(?=\/)\/font>/', "[size=\\1]\\2[/size]", $text);
					$text = preg_replace('/<span style="font-family: ([^<]*?)">([^<]*?)<(?=\/)\/span>/', "[font=\"\\1\"]\\2[/font]", $text);
					$text = preg_replace('/<span style="font-size: ([^<]*?)px; line-height: normal">([^<]*?)<(?=\/)\/span>/', "[size=\\1]\\2[/size]", $text);
					$text = preg_replace('/<div style="text-align:([^<]*?)">([^<]*?)<(?=\/)\/div>/', "[align=\\1]\n\\2\n[/align]", $text);
					$text = preg_replace('/<span style="color: ([^<]*?)">([^<]*?)<(?=\/)\/span>/', '[color=$1]$2[/color]', $text);
				    $text = preg_replace('/<a href="([^<]*?)">([^<]*?)<(?=\/)\/a>/', '[url=$1]$2[/url]', $text);
                    $text = preg_replace('/<div class="spoiler">([^<]*?)<\/a>([^<]*?)<(?=\/)\/div>/', "[spoiler=\"\\1\"]\n\\2\n[/spoiler]", $text);
                }
                $text = strip_tags(html_entity_decode($text));
			}
			return $text;
		}

	    if ($message = tfile($content))
	    {
		    $id = tfile($content, 'torrent');
		    $torrent = file_get_contents("http://tfile.ru/forum/download.php?id=". $id ."&uk=1111111111");
		    $new_name = md5($torrent);
		    $file = fopen('files/'. $new_name .'.torrent', 'w');
			fputs($file, $torrent);
	        fclose($file);

		    $hidden_form_fields .= '<input type="hidden" name="add_attachment_body" value="0" />';
			$hidden_form_fields .= '<input type="hidden" name="posted_attachments_body" value="0" />';
			$hidden_form_fields .= '<input type="hidden" name="attachment_list[]" value="files/'. $new_name .'.torrent" />';
			$hidden_form_fields .= '<input type="hidden" name="filename_list[]" value="torrent ('. create_date($bb_cfg['post_date_format'], TIMENOW) .')" />';
			$hidden_form_fields .= '<input type="hidden" name="extension_list[]" value="torrent" />';
			$hidden_form_fields .= '<input type="hidden" name="mimetype_list[]" value="application/x-bittorrent" />';
			$hidden_form_fields .= '<input type="hidden" name="filesize_list[]" value="'. filesize('files/'. $new_name .'.torrent') .'" />';
	        $hidden_form_fields .= '<input type="hidden" name="filetime_list[]" value="'. TIMENOW .'" />';
	        $hidden_form_fields .= '<input type="hidden" name="attach_id_list[]" value="" />';
	        $hidden_form_fields .= '<input type="hidden" name="attach_thumbnailsnail_list[]" value="0" />';

	    }
	    $subject = tfile($content, 'title');
    }
    elseif($_POST['tracker'] == 'lostfilm')
    {
    	if (!preg_match("/http:\/\/lostfilm.tv\/details.php\?id=/", $url))
	    {
	    	meta_refresh('', '2');
	    	bb_die("false link<script>alert('false link http://lostfilm.tv/details.php?id=xxxx');</script>");
	    }

    	$content = file_get_contents($url);
	    $content = iconv('windows-1251', 'UTF-8', $content);
	    $pos = strpos($content, '<a href="javascript:{}" onClick="ShowHappyUsers');
		$content = substr($content, 0, $pos);
  	    if (!$content)
	    {
	    	meta_refresh('', '2');
	    	bb_die('false content');
	    }

	    function lostfilm($text, $mode=false)
		{
			if($mode == 'title')
			{
				preg_match_all ("#\.\:\|\:\..*?\. ([\s\S]*?)</title>#", $text, $source, PREG_SET_ORDER);
			    $text = $source[0][1];
		    }
		    elseif($mode == 'torrent')
		    {
		    	preg_match_all ('#<a href="/download.php/(.*?)/(.*?).torrent" onMouseOver=".*?" class="a_download">#', $text, $source, PREG_SET_ORDER);
			    $text = $source[0];
		    }
		    else
		    {
				$text = preg_replace('/([\r\n])[\s]+/is', "\\1", $text);
				preg_match_all ("#class=\"a_download\"></a>\n</div>\n<div>([\s\S]*?)\n<br />\n<br />\n<b>#si", $text, $source, PREG_SET_ORDER);
			    $text = $source[0][1];

				$text = preg_replace('/<br.*?>/', "", $text);
                $text = preg_replace('/<img src="([\s\S]*?)" alt="" \/>/', '[img]$1[/img]', $text);

                $text = str_replace('<strong>', '[b]', $text);
                $text = str_replace('</strong>', '[/b]', $text);

                $text = str_replace(' target="_blank"', '', $text);

                $text = str_replace('&#039;', "'", $text);
				$text = str_replace('&nbsp;', ' ', $text);
				$text = str_replace('&gt;', '>', $text);
				$text = str_replace('&lt;', '<', $text);

				for ($i=0; $i<=20; $i++)
				{
					$text = preg_replace('/<b.*?>([^<]*?)<(?=\/)\/b>/', '[b]$1[/b]', $text);
					$text = preg_replace('/<i>([^<]*?)<(?=\/)\/i>/', '[i]$1[/i]', $text);
					$text = preg_replace('/<u>([^<]*?)<(?=\/)\/u>/', '[u]$1[/u]', $text);
					$text = preg_replace('/<s>([^<]*?)<(?=\/)\/s>/', '[s]$1[/s]', $text);
					$text = preg_replace('/<font color="([^<]*?)">([^<]*?)<(?=\/)\/font>/', '[color=$1]$2[/color]', $text);
				    $text = preg_replace('/<a href="([^<]*?)">([^<]*?)<(?=\/)\/a>/', '[url=http://www.lostfilm.tv$1]$2[/url]', $text);
                }
                $text = strip_tags(html_entity_decode($text));
			}
			return $text;
		}

		if ($message = lostfilm($content))
	    {
		    $snoopy = new Snoopy;
			$snoopy->host = "lostfilm.tv";
			$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
			$snoopy->referer = "http://lostfilm.tv/";
			$snoopy->rawheaders["Pragma"] = "no-cache";
            $snoopy->cookies = array (
                'pass'             => '123321',
	            'phpbb2mysql_data' => urldecode(''),
	            'phpbb2mysql_sid'  => '',
	            'uid'              => '1741046',
            );
            $snoopy->_httpmethod = "GET";
		    $snoopy->fetch($url);

		    $tor = lostfilm($content, 'torrent');
		    $id = $tor[1];
		    $name = $tor[2];

		    $snoopy->submit("http://lostfilm.tv/download.php/". $id ."/". $name .".torrent");
		    $torrent = $snoopy->results;
		    $tor = bdecode($torrent);
		    if(count($tor))
		    {
			    $new_name = md5($torrent);
			    $file = fopen('files/'. $new_name .'.torrent', 'w');
				fputs($file, $torrent);
		        fclose($file);

			    $hidden_form_fields .= '<input type="hidden" name="add_attachment_body" value="0" />';
				$hidden_form_fields .= '<input type="hidden" name="posted_attachments_body" value="0" />';
				$hidden_form_fields .= '<input type="hidden" name="attachment_list[]" value="files/'. $new_name .'.torrent" />';
				$hidden_form_fields .= '<input type="hidden" name="filename_list[]" value="'. $name .'" />';
				$hidden_form_fields .= '<input type="hidden" name="extension_list[]" value="torrent" />';
				$hidden_form_fields .= '<input type="hidden" name="mimetype_list[]" value="application/x-bittorrent" />';
				$hidden_form_fields .= '<input type="hidden" name="filesize_list[]" value="'. filesize('files/'. $new_name .'.torrent') .'" />';
		        $hidden_form_fields .= '<input type="hidden" name="filetime_list[]" value="'. TIMENOW .'" />';
		        $hidden_form_fields .= '<input type="hidden" name="attach_id_list[]" value="" />';
		        $hidden_form_fields .= '<input type="hidden" name="attach_thumbnailsnail_list[]" value="0" />';
	        }
	    }
	    $subject = lostfilm($content, 'title');
    }
    elseif($_POST['tracker'] == 'uniongang')
       {
    	if (!preg_match("/http:\/\/uniongang.tv\/details.php\?id=/", $url))
	    {
	    	meta_refresh('', '2');
	    	bb_die("false link<script>alert('false link http://uniongang.tv/details.php?id=xxxx');</script>");
	    }

	    $snoopy = new Snoopy;
		$snoopy->host = "uniongang.tv";
		$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
		$snoopy->referer = "http://uniongang.tv/";
		$snoopy->rawheaders["Pragma"] = "no-cache";

    	$snoopy->cookies = array (
			'MG_2723'   => '5',
			'new_pass2' => 'b710d98227d2b5e13004fa0ec0edaa1e',
			'new_uid'   => '67882',
			'PHPSESSID' => 'pn52p4lasq3r4i1pmko3280dt6',
		);
		$snoopy->_httpmethod = "GET";
	    $snoopy->fetch($url);
	    $content = iconv('windows-1251', 'UTF-8', $snoopy->results);
	    $content = preg_replace('/([\r\n])[\s]+/is', "\\1", $content);
	    $pos = strpos($content, '<table width="100%" border="1" cellspacing="0" cellpadding="5">');
	    $content = substr($content, $pos);
	    $pos = strpos($content, '<form method="post" action="takerate.php">');
		$content = substr($content, 0, $pos);

		function uniongang($text, $mode=false)
		{
			if($mode == 'title')
			{
				preg_match_all ("#<a class=\"index\" href=\"download.php\?id=.*?\"><b>(.*?)</b></a>#", $text, $source, PREG_SET_ORDER);
			    $text = $source[0][1];
		    }
		    elseif($mode == 'torrent')
		    {
		    	preg_match_all ("#<a class=\"index\" href=\"download.php\?id=(.*?)\">#", $text, $source, PREG_SET_ORDER);
			    $text = $source[0][1];
		    }
		    else
		    {
				preg_match_all ("#\" /><br />([\s\S]*?)</td></tr>#", $text, $source, PREG_SET_ORDER);
				preg_match_all ('/<img class="linked-image" src="(.*?)" border="0"/', $text, $pic, PREG_SET_ORDER);
			    $poster = ($pic[0][1]) ? "[img=right]". $pic[0][1] ."[/img]" : "";
			    $text = $poster . $source[0][1];

                $text = str_replace('<textarea>', '', $text);
                $text = str_replace('</textarea>', '', $text);

                $text = str_replace('<br />', '', $text);
                $text = preg_replace('/<img class="linked-image" src="(.*?)".*?\/>/', "[img]\\1[/img]", $text);
                $text = preg_replace('/<img border="0" src=".*?">/', '', $text);

                $text = str_replace('&#039;', "'", $text);
				$text = str_replace('&nbsp;', ' ', $text);
				$text = str_replace('&gt;', '>', $text);
				$text = str_replace('&lt;', '<', $text);

				for ($i=0; $i<=20; $i++)
				{
					$text = preg_replace('/<b>([^<]*?)<(?=\/)\/b>/', '[b]$1[/b]', $text);
					$text = preg_replace('/<u>([^<]*?)<(?=\/)\/u>/', '[u]$1[/u]', $text);
					$text = preg_replace('/<i>([^<]*?)<(?=\/)\/i>/', '[i]$1[/i]', $text);
					$text = preg_replace('/<s>([^<]*?)<(?=\/)\/s>/', '[s]$1[/s]', $text);

					$text = preg_replace('/<font style="font-size: ([^<]*?)pt">([^<]*?)<(?=\/)\/font>/', "[size=\\1]\\2[/size]", $text);
					$text = preg_replace('/<span style="font-family: ([^<]*?);">([^<]*?)<(?=\/)\/span>/', "[font=\"\\1\"]\\2[/font]", $text);
					$text = preg_replace('/<span class="post-align" style="text-align: ([^<]*?);">([^<]*?)<(?=\/)\/span>/', "[align=\\1]\\2[/align]", $text);
					$text = preg_replace('/<span style="color: ([^<]*?)">([^<]*?)<(?=\/)\/span>/', '[color=$1]$2[/color]', $text);

					$text = preg_replace('/<a href="([^<]*?)" title=".*?">([^<]*?)<(?=\/)\/a>/', '[url=$1]$2[/url]', $text);
                    $text = preg_replace('/<a href="\/([^<]*?)">([^<]*?)<(?=\/)\/a>/', '[url=http://www.uniongang.tv/$1]$2[/url]', $text);
                    $text = preg_replace('/<div class="spoiler-wrap"><div class="spoiler-head folded clickable">([^<]*?)<\/div><div class="spoiler-body">([^<]*?)<(?=\/)\/div><(?=\/)\/div>/', "[spoiler=\"\\1\"]\n\\2\n[/spoiler]", $text);
				}

                $text = str_replace('</td></tr><tr>', '', $text);
                $text = preg_replace('/<td valign=middle align=right>(.*?)<\/td><td>/', "\n\n\\1: ", $text);
				$text = strip_tags(html_entity_decode($text));
			}
			return $text;
		}

		if ($message = uniongang($content))
	    {
		    $id = uniongang($content, 'torrent');

	        $snoopy->submit("http://uniongang.tv/download.php?id=". $id);
		    $torrent = $snoopy->results;
		    $tor = bdecode($torrent);
		    if(count($tor))
		    {
			    $new_name = md5($torrent);
			    $file = fopen('files/'. $new_name .'.torrent', 'w');
				fputs($file, $torrent);
		        fclose($file);

			    $hidden_form_fields .= '<input type="hidden" name="add_attachment_body" value="0" />';
				$hidden_form_fields .= '<input type="hidden" name="posted_attachments_body" value="0" />';
				$hidden_form_fields .= '<input type="hidden" name="attachment_list[]" value="files/'. $new_name .'.torrent" />';
				$hidden_form_fields .= '<input type="hidden" name="filename_list[]" value="torrent ('. create_date($bb_cfg['post_date_format'], TIMENOW) .')" />';
				$hidden_form_fields .= '<input type="hidden" name="extension_list[]" value="torrent" />';
				$hidden_form_fields .= '<input type="hidden" name="mimetype_list[]" value="application/x-bittorrent" />';
				$hidden_form_fields .= '<input type="hidden" name="filesize_list[]" value="'. filesize('files/'. $new_name .'.torrent') .'" />';
		        $hidden_form_fields .= '<input type="hidden" name="filetime_list[]" value="'. TIMENOW .'" />';
		        $hidden_form_fields .= '<input type="hidden" name="attach_id_list[]" value="" />';
		        $hidden_form_fields .= '<input type="hidden" name="attach_thumbnailsnail_list[]" value="0" />';
	        }
	    }
	    $subject = uniongang($content, 'title');
    }
    elseif($_POST['tracker'] == 'nnmclub')
    {
    	if (!preg_match("/http:\/\/nnm-club.ru\/forum\/viewtopic.php\?t=/", $url))
	    {
	    	meta_refresh('', '2');
	    	bb_die($lang['REL_PAGE_WARN']."<script>alert('False link: http://nnm-club.ru/forum/viewtopic.php?t=xxxx');</script>");
	    }

	    $snoopy = new Snoopy;
		$snoopy->host = "nnm-club.ru";
		$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
		$snoopy->referer = "http://nnm-club.ru/";
		$snoopy->rawheaders["Pragma"] = "no-cache";

		$submit_url = "http://nnm-club.ru/forum/login.php";
		$snoopy->_submit_method = "POST";
		$submit_vars = array (
			'username' => "GliX",
			'password' => "1234",
			'invite'   => "",
			'login'    => $lang['LOGIN'],
		);
		$snoopy->submit($submit_url, $submit_vars);

	    $snoopy->_httpmethod = "GET";
	    $snoopy->fetch($url);
	    $content = $snoopy->results;
	    $pos = strpos($content, '<img src="images/icon_arrow.gif"');
		$content = substr($content, 0, $pos);

	    if (!$content)
	    {
	    	meta_refresh('', '2');
	    	bb_die('false content');
	    }

	    function nnmclub($text, $mode=false)
		{
			if($mode == 'title')
			{
				preg_match_all ("#<a class=\"maintitle\" href=\"viewtopic.php\?t=.*?\">(.*?)</a>#", $text, $source, PREG_SET_ORDER);
			    $text = $source[0][1];
			}
		    elseif($mode == 'torrent')
		    {
		    	preg_match_all ("#style=\"padding: 3px\"><b>(.*?).torrent</b></td>[\s\S]*?<a href=\"download.php\?id=(.*?)\" class=\"genmed\">#", $text, $source, PREG_SET_ORDER);
			    $text = $source[0];
		    }
		    else
		    {
				$pos = strpos($text, '<span class="postbody">');
				$text = substr($text, $pos);
				$pos = strpos($text, '<!-- //bt -->');
				$text = substr($text, 0, $pos);
                $text = str_replace('<span class="postbody">', '', $text);
                $text = str_replace('<!--/spoiler-body-->', '', $text);
                $text = str_replace('<!--/spoiler-wrap-->', '', $text);
				
                $text = preg_replace('/([\r\n])[\s]+/is', "\\1", $text);

				$text = preg_replace('/<img src=".*?" alt=".*?" border="0"\/>/', '', $text);
				$text = str_replace('<hr />', "[hr]", $text);
                $text = preg_replace('/<var class="postImg" title="(.*?)">&#10;<\/var>/', '[img]$1[/img]', $text);
				$text = preg_replace('/<var class="postImg postImgAligned img-(.*?)" title="(.*?)">&#10;<\/var>/', "[img=\\1]\\2[/img]\n", $text);
				$text = str_replace('<span class="post-br"><br /></span>', "\n[br]\n", $text);

				$text = str_replace('<br />', "\n", $text);
				$text = str_replace('<ul>', '[list]', $text);
				$text = str_replace('</ul>', '[/list]', $text);
				$text = str_replace('<li>', "\n[*]", $text);
				$text = str_replace('</li>', '', $text);
				$text = str_replace('<div class="spoiler-wrap">', '', $text);
				$text = str_replace('<center>', "[align=center]", $text);
                $text = str_replace('</center>', "[/align]", $text);

				for ($i=0; $i<=20; $i++)
				{
					$text = preg_replace('/<span style="font-weight: bold">([^<]*?)<(?=\/)\/span>/', '[b]$1[/b]', $text);
					$text = preg_replace('/<span style="text-decoration: underline">([^<]*?)<(?=\/)\/span>/', '[u]$1[/u]', $text);
					$text = preg_replace('/<span style="font-style: italic">([^<]*?)<(?=\/)\/span>/', '[i]$1[/i]', $text);
					$text = preg_replace('/<span style="text-decoration: line-through">([^<]*?)<(?=\/)\/span>/', '[s]$1[/s]', $text);
					$text = preg_replace('/<span style="font-size: ([^<]*?)px; line-height: normal">([^<]*?)<(?=\/)\/span>/', "[size=\\1]\\2[/size]", $text);
					$text = preg_replace('/<span style="font-family: ([^<]*?)">([^<]*?)<(?=\/)\/span>/', "[font=\"\\1\"]\\2[/font]", $text);
					$text = preg_replace('/<span style="text-align: ([^<]*?); display: block;">([^<]*?)<(?=\/)\/span>/', "[align=\\1]\n\\2\n[/align]", $text);
                    $text = preg_replace('/<span style="color: ([^<]*?)">([^<]*?)<(?=\/)\/span>/', '[color=$1]$2[/color]', $text);
					$text = preg_replace('/<a href="(.*?)".*?class="postLink">([^<]*?)<(?=\/)\/a>/', '[url=$1]$2[/url]', $text);
					$text = preg_replace('/<div class="spoiler-body">([^<]*?)<(?=\/)\/div><(?=\/)\/div>/', '[spoiler]$1[/spoiler]', $text);
				    $text = preg_replace('/<div class="spoiler-body" title="([^<]*?)">([^<]*?)<(?=\/)\/div><(?=\/)\/div>/', '[spoiler="$1"]$2[/spoiler]', $text);
				}
				$text = str_replace('</span>', '', $text);
				$text = strip_tags(html_entity_decode($text)); 
			}
			return $text;
		}

		if ($message = nnmclub($content))
	    {
		    $tor = nnmclub($content, 'torrent');
		    $id = $tor[2];
		    $name = $tor[1];

		    $snoopy->submit("http://nnm-club.ru/forum/download.php?id=". $id);
		    $torrent = $snoopy->results;
		    $new_name = md5($torrent);

		    $file = fopen('files/'. $new_name .'.torrent', 'w');
			fputs($file, $torrent);
	        fclose($file);

		    $hidden_form_fields .= '<input type="hidden" name="add_attachment_body" value="0" />';
			$hidden_form_fields .= '<input type="hidden" name="posted_attachments_body" value="0" />';
			$hidden_form_fields .= '<input type="hidden" name="attachment_list[]" value="files/'. $new_name .'.torrent" />';
			$hidden_form_fields .= '<input type="hidden" name="filename_list[]" value="'. $name .'" />';
			$hidden_form_fields .= '<input type="hidden" name="extension_list[]" value="torrent" />';
			$hidden_form_fields .= '<input type="hidden" name="mimetype_list[]" value="application/x-bittorrent" />';
			$hidden_form_fields .= '<input type="hidden" name="filesize_list[]" value="'. filesize('files/'. $new_name .'.torrent') .'" />';
	        $hidden_form_fields .= '<input type="hidden" name="filetime_list[]" value="'. TIMENOW .'" />';
	        $hidden_form_fields .= '<input type="hidden" name="attach_id_list[]" value="" />';
	        $hidden_form_fields .= '<input type="hidden" name="attach_thumbnail_list[]" value="0" />';
	    }
	    $subject = nnmclub($content, 'title');
    }
	elseif($_POST['tracker'] == 'kaztorka')
    {
        if (!preg_match("/http:\/\/kaztorka.org\/torrent\/info\?torrentID=/", $url))
	    {
	    	meta_refresh('', '2');
	    	bb_die("false link<script>alert('false link http://kaztorka.org/details.php?id=xxxx');</script>");
	    }

	    $snoopy = new Snoopy;
		$snoopy->host = "kaztorka.org";
		$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
		$snoopy->referer = "http://kaztorka.org/";
		$snoopy->rawheaders["Pragma"] = "no-cache";

		$submit_url = "http://kaztorka.org/auth/login";
		$snoopy->_submit_method = "POST";
		$submit_vars = array (
			'username' => "ZerocooL",
			'password' => "14061987",
		);
		$snoopy->submit($submit_url, $submit_vars);

	    $snoopy->_httpmethod = "GET";
	    $snoopy->fetch($url);
	    $content = $snoopy->results;
	    $content = preg_replace('/([\r\n])[\s]+/is', "\\1", $content);
	    $pos = strpos($content, '<td class="header" align="right" width="120">Категория</td>');
		$content = substr($content, 0, $pos);

	    if (!$content)
	    {
	    	meta_refresh(BB_ROOT, '2');
	    	bb_die('false content');
	    }

        function kaztorka($text, $mode=false)
		{
if($mode == 'title')
               {
                    preg_match_all ('#id="filename">(.*?)</td>#', $text, $source, PREG_SET_ORDER);
                   $text = $source[0];
              }


		    if($mode == 'poster')
			{
				preg_match_all ('#<img src = "(.*?)\?.*? id = "images4"/>#', $text, $source, PREG_SET_ORDER);
			    $text = $source[0][1];
		    }
		    elseif($mode == 'screen_shots')
		    {
		    	preg_match_all ('#<a href="(.*?)\?.*?" class="highslide" onclick="return hs\.expand\(this\)">#', $text, $source, PREG_SET_ORDER);
			    $text = $source;
		    }
		    elseif($mode == 'torrent')
		    {
		    	$text = str_replace('info?torrentID', 'downloadcheck?infohash', $text);
		    }
		    else
		    {
				@preg_match_all ("#id='description'>([\s\S]*?)</td>#", $text, $source, PREG_SET_ORDER);
				@$text = $source[0][1];

                $text = str_replace('<br />', '', $text);
                $text = preg_replace('/<img src="(.*?)" alt="" \/>/', "[img]\\1[/img]", $text);

                $text = preg_replace('/<div class=\'spoilertop\' style=\'cursor:pointer;\' onclick="show_hide_text\(this\)">(.*?) Ў<\/div>/msie', "'<div class=\'spoilertop\' style=\'cursor:pointer;\' onclick=\"show_hide_text(this)\">'. strip_tags('\\1') .' Ў</div>'", $text);
                $text = str_replace('&#039;', "'", $text);
				$text = str_replace('&nbsp;', ' ', $text);
				$text = str_replace('&gt;', '>', $text);
				$text = str_replace('&lt;', '<', $text);

                $text = str_replace(' class="bb"', '', $text);
                $text = str_replace('<strong>', '[b]', $text);
                $text = str_replace('</strong>', '[/b]', $text);

				for ($i=0; $i<=20; $i++)
				{
					$text = preg_replace('/<u>([^<]*?)<(?=\/)\/u>/', '[u]$1[/u]', $text);
					$text = preg_replace('/<i>([^<]*?)<(?=\/)\/i>/', '[i]$1[/i]', $text);
					$text = preg_replace('/<s>([^<]*?)<(?=\/)\/s>/', '[s]$1[/s]', $text);

					$text = preg_replace('/<font size="([^<]*?)">([^<]*?)<(?=\/)\/font>/msie', "'[size='. ('$1'*4) .']\\2[/size]'", $text);
					$text = preg_replace('/<font face="([^<]*?)">([^<]*?)<(?=\/)\/font>/', "[font=\"\\1\"]\\2[/font]", $text);
					$text = preg_replace('/<div align="([^<]*?)">([^<]*?)<(?=\/)\/div>/', "[align=\\1]\\2[/align]", $text);
					$text = preg_replace('/<font color="([^<]*?)">([^<]*?)<(?=\/)\/font>/', '[color=$1]$2[/color]', $text);

					$text = preg_replace('/<a href="([^<]*?)">([^<]*?)<(?=\/)\/a>/', '[url=$1]$2[/url]', $text);
                    $text = preg_replace('/<div><div class=\'spoilertop\' style=\'cursor:pointer;\' onclick="show_hide_text\(this\)">([^<]*?) Ў<\/div><div class=\'spoilermain\' style="display:none">([^<]*?)<(?=\/)\/div><(?=\/)\/div>/', "[spoiler=\"\\1\"]\\2[/spoiler]", $text);
                    $text = preg_replace('/<div class="bb_code"><div class="bb_code_header">.*?<\/div>([^<]*?)<(?=\/)\/div>/', '[code]$1[/code]', $text);
                }
                $text = strip_tags(stripslashes(html_entity_decode($text)));
			}
			return $text;
		}
	    $subject = kaztorka($content, 'title');
	    if ($message = kaztorka($content))
	    {
		    $url = kaztorka($url, 'torrent');
		    $snoopy->fetch($url);
		    $text = $snoopy->results;
			    preg_match_all ('#<img src="http://kaztorka.org/images/torrent[\s\S]*?<a href="(.*?)">#', $text, $source, PREG_SET_ORDER);
			$url = $source[0][1];
				preg_match_all ('#&f=(.*?)&key#', urldecode($url), $source, PREG_SET_ORDER);
			$name = addslashes($source[0][1]);

			$snoopy->submit($url);
		    $torrent = $snoopy->results;
		    $tor = bdecode($torrent);

		    if(count($tor))
		    {
			    //if((array_key_exists('announce-list', $tor)) || $tor['announce'])
			    //{
				    $new_name = md5($torrent);
				    $file = fopen('files/'. $new_name .'.torrent', 'w');
					fputs($file, $torrent);
			        fclose($file);

				    $hidden_form_fields .= '<input type="hidden" name="add_attachment_body" value="0" />';
					$hidden_form_fields .= '<input type="hidden" name="posted_attachments_body" value="0" />';
					$hidden_form_fields .= '<input type="hidden" name="attachment_list[]" value="files/'. $new_name .'.torrent" />';
					$hidden_form_fields .= '<input type="hidden" name="filename_list[]" value="'. $name .'" />';
					$hidden_form_fields .= '<input type="hidden" name="extension_list[]" value="torrent" />';
					$hidden_form_fields .= '<input type="hidden" name="mimetype_list[]" value="application/x-bittorrent" />';
					$hidden_form_fields .= '<input type="hidden" name="filesize_list[]" value="'. filesize('files/'. $new_name .'.torrent') .'" />';
			        $hidden_form_fields .= '<input type="hidden" name="filetime_list[]" value="'. TIMENOW .'" />';
			        $hidden_form_fields .= '<input type="hidden" name="attach_id_list[]" value="" />';
			        $hidden_form_fields .= '<input type="hidden" name="attach_thumbnail_list[]" value="0" />';
		        //}
		    }
		    $poster = pic_uploud_url(kaztorka($content, 'poster'), '=right');

		    $screen_shots = "\n[spoiler=\"Скриншоты\"]\n";
		    foreach(kaztorka($content, 'screen_shots') as $screen)
		    {
		    	$screen_shots .= pic_uploud_url($screen[1]) ."\n";
		    }
		    $screen_shots .= "[/spoiler]";
		    $screen_shots;

		    $message = $poster . $message . $screen_shots;
	    }	    
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	elseif($_POST['tracker'] == 'piratbit')
    {
        if (!preg_match("/http:\/\/piratbit.net\/viewtopic.php\?t=/", $url))
	    {
	    	meta_refresh('', '2');
	    	bb_die("false link<script>alert('false link http://piratbit.net/viewtopic.php?t=xxxx');</script>");
	    }

	    $snoopy = new Snoopy;
		$snoopy->host = "piratbit.net";
		$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
		$snoopy->referer = "http://piratbit.net/";
		$snoopy->rawheaders["Pragma"] = "no-cache";

		$submit_url = "http://piratbit.net/login.php";
		$snoopy->_submit_method = "POST";
		$submit_vars = array (
			'login_username' => "ZerocooL1143", //логин
			'login_password' => "123", //пароль
			'login' => $lang['LOGIN'],
		);
		$snoopy->submit($submit_url, $submit_vars);

	    $snoopy->_httpmethod = "GET";
	    $snoopy->fetch($url);
	    $content = iconv('windows-1251', 'UTF-8', $snoopy->results);
	    $pos = strpos($content, '<div class="spacer_12"></div>');
		$content = substr($content, 0, $pos);

	    if (!$content)
	    {
	    	meta_refresh('', '2');
	    	bb_die('false content');
	    }

	    function piratbit($text, $mode=false)
		{
			if($mode == 'title')
			{
				preg_match_all ("#<H1 class=\"maintitle\"><a href=\".*?\">([\s\S]*?)</a></H1>#", $text, $source, PREG_SET_ORDER);
			    $text = $source[0][1];
				$text = str_replace('<wbr>', '', $text);
		    }
		    elseif($mode == 'torrent')
		    {

				preg_match_all ("#<th colspan=\"3\" class=\"genmed\"><p>(.*?).torrent<table width=\"100%\" border=\"0\">[\s\S]*?<a href=\"download.php\?id=(.*?)\" #", $text, $source, PREG_SET_ORDER);
			    $text = $source[0];
		    }
		    else
		    {
				$pos = strpos($text, '<div class="post_body"');
				$text = substr($text, $pos);
				$pos = strpos($text, '<div class="spacer_8"></div>');
				$text = substr($text, 0, $pos);
                $text = preg_replace('/<div class="post_body">/', '', $text);
                $text = str_replace('<wbr>', '', $text);
                $text = preg_replace('/([\r\n])[\s]+/is', "\\1", $text);
				//preg_match_all ("#<div class=\"post_body\" id=\".*?\">([\s\S]*?)<div class=\"clear\"></div>#", $text, $source, PREG_SET_ORDER);
			    //$text = $source[0][1];

				$text = preg_replace('/<img class="smile" src=".*?" align="absmiddle" border="0" \/>/', '', $text);
                $text = str_replace('<div class="clear"></div>', '', $text);
                $text = preg_replace('/<!--\/.*?-->/', '', $text);
				$text = str_replace('<hr noshade color=\'#000000\' size=\'1\'>', "\n[hr]\n", $text);
				$text = str_replace('<hr />', "\n[hr]\n", $text);
                $text = preg_replace('/<var class="postImg" title="(.*?)">&#10;<\/var>/', '[img]$1[/img]', $text);
				$text = preg_replace('/<var class="postImg postImgAligned img-(.*?)" title="([\s\S]*?)">&#10;<\/var>/', "[img=\\1]\\2[/img]\n", $text);
				
                $text = preg_replace('/<div class="postImg-wrap" style=".*?" align="center"><img src="(.*?)" id="postImgAligned" class="postImg" alt="pic" \/><\/div>/', "[align=center][img]\\1[/img][/align]\n", $text);
				$text = preg_replace('/<div class="postImg-wrap" style=".*?" align="(.*?)"><img src="(.*?)" id="postImgAligned" class="postImg" alt="pic" \/><\/div>/', "[img=\\1]\\2[/img]\n", $text);
				$text = preg_replace('/<img src="(.*?)" id="postImg" class="postImg" align="absmiddle" hspace="0" vspace="4" alt="pic" \/>/', '[img]$1[/img]', $text);
                
				$text = preg_replace('/<a href="([^<]*?)" rel=".*?"><img src=".*?" \/>&nbsp;<\/a>/', '[thumbnails]$1[/thumbnails]', $text);
				$text = str_replace('<ul>', '[list]', $text);
				$text = str_replace('</ul>', '[/list]', $text);
				$text = str_replace('<li>', "\n[*]", $text);
				$text = str_replace('</li>', '', $text);
				$text = str_replace('<br /><br />', "\n", $text);
				$text = str_replace('<br clear="all" />', "\n[br]\n", $text);
				$text = str_replace('<div></div>', "\n", $text);
				$text = str_replace('<div', '<span', $text);
                $text = str_replace('</div>', '</span>', $text);
                $text = str_replace('<a', '<span', $text);
                $text = str_replace('</a>', '</span>', $text);

                $text = str_replace('&#039;', "'", $text);
				$text = str_replace('&nbsp;', ' ', $text);
				$text = str_replace('&gt;', '>', $text);
				$text = str_replace('&lt;', '<', $text);

				for ($i=0; $i<=20; $i++)
				{
					$text = preg_replace('/<span style="font-weight: bold;">([^<]*?)<(?=\/)\/span>/', '[b]$1[/b]', $text);
					$text = preg_replace('/<span style="text-decoration: underline;">([^<]*?)<(?=\/)\/span>/', '[u]$1[/u]', $text);
					$text = preg_replace('/<span style="font-style: italic;">([^<]*?)<(?=\/)\/span>/', '[i]$1[/i]', $text);
					$text = preg_replace('/<span style="font-size: ([^<]*?)px; line-height: normal;">([^<]*?)<(?=\/)\/span>/', "[size=\\1]\\2[/size]", $text);
					$text = preg_replace('/<span style="font-family: ([^<]*?)">([^<]*?)<(?=\/)\/span>/', "[font=\"\\1\"]\\2[/font]", $text);
					$text = preg_replace('/<span style="text-align: ([^<]*?);">([^<]*?)<(?=\/)\/span>/', "[align=\\1]\n\\2\n[/align]", $text);
					$text = preg_replace('/<span style="color: ([^<]*?);">([^<]*?)<(?=\/)\/span>/', '[color=$1]$2[/color]', $text);

					$text = preg_replace('/<span href="([^<]*?)" class="postLink">([^<]*?)<(?=\/)\/span>/', '[url=$1]$2[/url]', $text);
					$text = preg_replace('/<div class="sp-body" title="([^<]*?)">([^<]*?)<(?=\/)\/div>([\s\S]*?)<([^<]*?)\/div>/', "[spoiler=\"\\1\"]\n\\2\n[/spoiler]", $text);
					$text = preg_replace('/<div class="sp-body">([^<]*?)<(?=\/)\/div>([\s\S]*?)<([^<]*?)\/div>/', "[spoiler]\n\\1\n[/spoiler]", $text);
					$text = preg_replace('/<div class="q">([^<]*?)<(?=\/)\/div>([^<]*?)<([^<]*?)\/div>/', "[quote]\n\\1\n[/quote]", $text);
					$text = preg_replace('/<div class="q" head="([^<]*?)">([^<]*?)<(?=\/)\/div>([\s\S]*?)<([^<]*?)\/div>/', "[quote=\"\\1\"]\n\\2\n[/quote]", $text);
					$text = preg_replace('/<div class="c-head"><b>([^<]*?)<\/b><\/div>([^<]*?)<div class="c-body">([^<]*?)<(?=\/)\/div>([\s\S]*?)<([^<]*?)\/div>/', "[code]\n\\3\n[/code]", $text);
				
					
					$text = preg_replace('/<p class="q_head"><b>.*?<\/b><\/p>[\s\S]*?<div class="q">([^<]*?)<(?=\/)\/div><!--\/q-->/', "[quote]\n\\1\n[/quote]", $text);
					$text = preg_replace('/<p class="q_head"><b>(.*?)<\/b>.*?<\/p>[\s\S]*?<div class="q">([^<]*?)<(?=\/)\/div><!--\/q-->/', "[quote=\"\\1\"]\n\\2\n[/quote]", $text);
					$text = preg_replace('/<span class="code">([^<]*?)<(?=\/)\/span>/', "[code]\n\\1\n[/code]", $text);

			    }

			    // Убираем пустое пространство
				$text = preg_replace('/([\r\n])[\s]+/is', "\\1", $text);
				$text = strip_tags(html_entity_decode($text));
			}
			return $text;
		}

	    if ($message = piratbit($content))
	    {
		    $tor = piratbit($content, 'torrent');;
            $id = $tor[2];
            $name = $tor[1];

	        $snoopy->submit("http://piratbit.net/download.php?id=". $id);
		    $torrent = $snoopy->results;
		    $tor = bdecode($torrent);
		    if(count($tor))
		    {
			    $new_name = md5($torrent);
			    $file = fopen('files/'. $new_name .'.torrent', 'w');
				fputs($file, $torrent);
		        fclose($file);

			    $hidden_form_fields .= '<input type="hidden" name="add_attachment_body" value="0" />';
				$hidden_form_fields .= '<input type="hidden" name="posted_attachments_body" value="0" />';
				$hidden_form_fields .= '<input type="hidden" name="attachment_list[]" value="files/'. $new_name .'.torrent" />';
				$hidden_form_fields .= '<input type="hidden" name="filename_list[]" value="'. $name .'" />';
				$hidden_form_fields .= '<input type="hidden" name="extension_list[]" value="torrent" />';
				$hidden_form_fields .= '<input type="hidden" name="mimetype_list[]" value="application/x-bittorrent" />';
				$hidden_form_fields .= '<input type="hidden" name="filesize_list[]" value="'. filesize('files/'. $new_name .'.torrent') .'" />';
		        $hidden_form_fields .= '<input type="hidden" name="filetime_list[]" value="'. TIMENOW .'" />';
		        $hidden_form_fields .= '<input type="hidden" name="attach_id_list[]" value="" />';
		        $hidden_form_fields .= '<input type="hidden" name="attach_thumbnailsnail_list[]" value="0" />';
            }
	    }
	    $subject = piratbit($content, 'title');
    }
elseif($_POST['tracker'] == 'piratca')
    {
        if (!preg_match("/http:\/\/pirat.ca\/topic\//", $url))
	    {
	    	meta_refresh('', '2');
	    	bb_die("false link<script>alert('false link http://pirat.ca/topic/xxxx');</script>");
	    }

		
		
	    $snoopy = new Snoopy;
		$snoopy->host = "pirat.ca";
		$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
		$snoopy->referer = "http://pirat.ca/";
		$snoopy->rawheaders["Pragma"] = "no-cache";

		$submit_url = "http://pirat.ca/forum/login.php";
		$snoopy->_submit_method = "POST";
		$submit_vars = array (
			'login_username' => "WinDXD",
			'login_password' => "Yccrrggz",
			'login' => $lang['LOGIN'],
		);
		$snoopy->submit($submit_url, $submit_vars);

	    $snoopy->_httpmethod = "GET";
	    $snoopy->fetch($url);
		$content = iconv('windows-1251', 'UTF-8', $snoopy->results);
	    $pos = strpos($content, '<div class="spacer_12"></div>');
		$content = substr($content, 0, $pos);

	    if (!$content)
	    {
	    	meta_refresh(BB_ROOT, '2');
	    	bb_die('false content');
	    }

	    function piratca($text, $mode=false)
		{
			if($mode == 'title')
			{
				preg_match_all ("#<h1 class=\"maintitle\"><a href=\".*?\">([\s\S]*?)</a>#", $text, $source, PREG_SET_ORDER);
			    $text = $source[0][1];
				$text = str_replace('<wbr>', '', $text);
				$text = str_replace('</wbr>', '', $text);
			}
		    elseif($mode == 'torrent')
		    {
		    	preg_match_all ('#<th colspan="3" class="genmed">(.*?)</th>[\s\S]*?dl_torr\(\'id=(.*?)\'\)#', $text, $source, PREG_SET_ORDER);
			    $text = $source[0];
		    }
		    else
		    {
				$pos = strpos($text, '<div class="post_body"');
				$text = substr($text, $pos);
				$pos = strpos($text, '<div class="spacer_8"></div>');
				$text = substr($text, 0, $pos);
                $text = str_replace('<div class="post_body">', '', $text);
                $text = str_replace('<wbr>', '', $text);

				//preg_match_all ("#<div class=\"post_body\" id=\".*?\">([\s\S]*?)<div class=\"clear\"></div>#", $text, $source, PREG_SET_ORDER);
			    //$text = $source[0][1];

				$text = preg_replace('/<img class="smile" src=".*?" align="absmiddle" border="0" \/>/', '', $text);
                $text = str_replace('<div class="clear"></div>', '', $text);
                $text = str_replace('<div class="q_wrap">', '', $text);

                $text = preg_replace('/<div style="display: none;">.*?<\/div>/', '', $text);

				$text = str_replace('<hr />', "\n[hr]\n", $text);
				$text = str_replace('<div class="spoiler-wrap">', '', $text);

				$text = preg_replace('/<img src="(.*?)" .*?>/', '[img]$1[/img]', $text);
				
				$text = preg_replace('/<var class="postImg postImgAligned img-(.*?)" title="([\s\S]*?)">&#10;<\/var>/', "[img=\\1]\\2[/img]\n", $text);
				
				$text = preg_replace('/<a href="([^<]*?)" rel=".*?"><img src=".*?" \/>&nbsp;<\/a>/', '[thumbnails]$1[/thumbnails]', $text);
				$text = str_replace('<ul>', '[list]', $text);
				$text = str_replace('</ul>', '[/list]', $text);
				$text = str_replace('<li>', "\n[*]", $text);
				$text = str_replace('</li>', '', $text);
				$text = str_replace('<ol type="1">', '[list=1]', $text);
				$text = str_replace('<ol type="a">', '[list=a]', $text);
				$text = str_replace('</ol>', '[/list]', $text);
				$text = str_replace('', "\n", $text);
				$text = str_replace('<div></div>', "\n", $text);
                $text = preg_replace('/<a href="([^<]*?)" rel=".*?"><img src=".*?" \/>&nbsp;<\/a>/', '[img]$1[/img]', $text);
                $text = preg_replace('/<!--\/.*?-->/s', '', $text);

                $text = str_replace('<br clear="all" />', "\n[br]\n", $text);
                $text = str_replace('<br />', "\n", $text);

                $text = str_replace('<div', '<span', $text);
                $text = str_replace('</div>', '</span>', $text);
                $text = str_replace('<a', '<span', $text);
                $text = str_replace('</a>', '</span>', $text);

                $text = str_replace('&#039;', "'", $text);
				$text = str_replace('&nbsp;', ' ', $text);
				$text = str_replace('&gt;', '>', $text);
				$text = str_replace('&lt;', '<', $text);

				for ($i=0; $i<=20; $i++)
				{
					$text = preg_replace('/<span style="font-weight: bold;">([^<]*?)<(?=\/)\/span>/', '[b]$1[/b]', $text);
					$text = preg_replace('/<span style="text-decoration: underline;">([^<]*?)<(?=\/)\/span>/', '[u]$1[/u]', $text);
					$text = preg_replace('/<span style="font-style: italic;">([^<]*?)<(?=\/)\/span>/', '[i]$1[/i]', $text);
					$text = preg_replace('/<span style="font-size: ([^<]*?)px; line-height: normal;">([^<]*?)<(?=\/)\/span>/', "[size=\\1]\\2[/size]", $text);
					$text = preg_replace('/<span style="font-family: ([^<]*?)">([^<]*?)<(?=\/)\/span>/', "[font=\"\\1\"]\\2[/font]", $text);
					$text = preg_replace('/<span style="text-align: ([^<]*?);">([^<]*?)<(?=\/)\/span>/', "[align=\\1]\n\\2\n[/align]", $text);
					$text = preg_replace('/<span style="color: ([^<]*?);">([^<]*?)<(?=\/)\/span>/', '[color=$1]$2[/color]', $text);

					$text = preg_replace('/<span href="([^<]*?)" class="postLink">([^<]*?)<(?=\/)\/span>/', '[url=$1]$2[/url]', $text);
                    $text = preg_replace('/<span href="([^<]*?)" style="border: none;" class="highslide" .*?>([^<]*?)<(?=\/)\/span>/', '[url=$1]$2[/url]', $text);
                    $text = preg_replace('/<span class="postImg-wrap" style="float\: (.*?); .*?>\[img\](.*?)\[\/img\]<\/span>/', '[img=$1]$2[/img]', $text);

					$text = preg_replace('/<span class="spoiler-head folded clickable">(.*?)<\/span>[\s\S]*? class="spoiler-body">([^<]*?)<(?=\/)\/span>([^<]*?)<([^<]*?)\/span>/', "[spoiler=\"\\1\"]\n\\2\n[/spoiler]", $text);
					$text = preg_replace('/<p class="q_head"><b>(.*?)<\/b>[\s\S]*? class="q">([^<]*?)<(?=\/)\/span>([^<]*?)<([^<]*?)\/span>/', "[quote=\"\\1\"]\n\\2\n[/quote]", $text);
					$text = preg_replace('/<span class="q">([^<]*?)<(?=\/)\/span>([^<]*?)<([^<]*?)\/span>/', "[quote]\n\\1\n[/quote]", $text);
					$text = preg_replace('/<span class="code_wrap">[\s\S]*?<span class="code">([^<]*?)<([^<]*?)\/span>/', "[code]\n\\1\n[/code]", $text);
				}

			    // Убираем пустое пространство
				$text = preg_replace('/([\r\n])[\s]+/is', "\\1", $text);
				$text = strip_tags(html_entity_decode($text));
			}
			return $text;
		}

	    if($message = piratca($content))
	    {
		    $torr = piratca($content, 'torrent');
		    $name = addslashes($torr[1]);

            $snoopy->submit('http://pirat.ca/forum/dl.php?id='.$torr[2]);
		    $torrent = $snoopy->results;
		    $tor = bdecode($torrent);

		    if(count($tor))
		    {
			    //if((array_key_exists('announce-list', $tor)) || $tor['announce'])
			    //{
				    $new_name = md5($torrent);
				    $file = fopen('files/'. $new_name .'.torrent', 'w');
					fputs($file, $torrent);
			        fclose($file);

				    $hidden_form_fields .= '<input type="hidden" name="add_attachment_body" value="0" />';
					$hidden_form_fields .= '<input type="hidden" name="posted_attachments_body" value="0" />';
					$hidden_form_fields .= '<input type="hidden" name="attachment_list[]" value="files/'. $new_name .'.torrent" />';
					$hidden_form_fields .= '<input type="hidden" name="filename_list[]" value="'. $name .'" />';
					$hidden_form_fields .= '<input type="hidden" name="extension_list[]" value="torrent" />';
					$hidden_form_fields .= '<input type="hidden" name="mimetype_list[]" value="application/x-bittorrent" />';
					$hidden_form_fields .= '<input type="hidden" name="filesize_list[]" value="'. filesize('files/'. $new_name .'.torrent') .'" />';
			        $hidden_form_fields .= '<input type="hidden" name="filetime_list[]" value="'. TIMENOW .'" />';
			        $hidden_form_fields .= '<input type="hidden" name="attach_id_list[]" value="" />';
			        $hidden_form_fields .= '<input type="hidden" name="attach_thumbnail_list[]" value="0" />';
		        //}
		    }
	    }
	    $subject = piratca($content, 'title');
	}


    $hidden_form_fields .= '<input type="hidden" name="mode" value="newtopic" />';
	$hidden_form_fields .= '<input type="hidden" name="'. POST_FORUM_URL .'" value="'.$forum_id.'" />';

    generate_smilies('inline');

$template->assign_vars(array(
	    'SUBJECT'            => $subject,
	    'MESSAGE'            => $message,
        'S_POST_ACTION'      => append_sid("posting.php"),

	    'SUBJECT'            => $subject,
	    'MESSAGE'            => $message,
        'S_POST_ACTION'      => append_sid("posting.php"),
		
		'POSTING_SUBJECT'    => true,
		'S_HIDDEN_FORM_FIELDS' => $hidden_form_fields,
	));
}

$template->assign_vars(array(
    'PAGE_TITLE'=> 'Grabber Trackers (rutracker.org  rutor.org  tfile.ru  anidub.com  pornolab.net lostfilm.tv uniongang.tv nnm-club.ru tapochek.net rustorka.com)',
));

print_page('posting.tpl');
?>